/*----------------------------------
 * wfutil1.5.0
 * */

//Variables generales
var url_master = "";
var options_gson = new Array();
var fechas = new Array();
var series = new Array();
var fe = 0; //cantidad para fechas
var se = 0; //cantidad para series
var dia;
var mes;
var anio;
function item_activo(item) {
    if (item.length > 0) {
        $D.g_ID(item).className = "menu-item1 active";
        try {
            $D.g_ID("menu1").className = "menu-item0 first-item";
        } catch (e) {
        }
    }
}

function rzCC(s) {
    for (var exp = /-([a-z])/;
            exp.test(s);
            s = s.replace(exp, RegExp.$1.toUpperCase()))
        ;
    return s;
}

function _setStyle(element, declaration) {
    if (declaration.charAt(declaration.length - 1) == ';')
        declaration = declaration.slice(0, -1);
    var k, v;
    var splitted = declaration.split(';');
    for (var i = 0, len = splitted.length; i < len; i++) {
        k = rzCC(splitted[i].split(':')[0]);
        v = splitted[i].split(':')[1];
        eval("element.style." + k + "='" + v + "'");
    }
}

function verselectormultiple(ID, V, P) {
    var opciones = options_gson[ID];
    var c = 0;
    $D.g_ID("m_table_body").innerHTML = "";
    $D.g_ID("BPM_T").innerHTML = "Titulo";
    for (var i = 0; i < opciones.length; i++) {
        var m_tr = $D.n_E("tr");
        var nu = 0;
        try {
            nu = parseInt(opciones[i].co_compag);
        } catch (ex) {
            nu = 0;
        }

        try {
            if (nu < 0) {
                var m_td2 = $D.n_E("td");
                m_td2.setAttribute("align", "center");
                m_td2.setAttribute("colspan", "2");
                m_td2.setAttribute("nowrap", "");
                m_td2.innerHTML = opciones[i].no_compag;
                m_tr.appendChild(m_td2);
            } else {
                var m_td1 = $D.n_E("td");
                var m_input = $D.n_E("input", "fruit", "checkbox", opciones[i].co_compag, null, null, "opt" + opciones[i].co_compag);
                m_td1.style.textAlign = "center";
                m_td1.appendChild(m_input);
                var m_td2 = $D.n_E("td");
                m_td2.setAttribute("id", "td" + i + "_2");
                m_td2.setAttribute("align", "left");
                m_td2.setAttribute("nowrap", "");
                m_td2.style.width = "99%";
                var m_label = $D.n_E("label", null, null, null, opciones[i].no_compag);
                m_label.setAttribute("for", "opt" + opciones[i].co_compag);
                m_td2.appendChild(m_label);
                m_tr.appendChild(m_td1);
                m_tr.appendChild(m_td2);
            }
        } catch (exp) {
        }

        $D.g_ID("m_table_body").appendChild(m_tr);
    }

    var b_td2 = $D.n_E("td");
    b_td2.setAttribute("align", "right");
    b_td2.style.border = "none";
    b_td2.style.width = "1%";
    $D.g_ID('b_guarda').style.display = "inline-block";
    $D.g_ID('b_guarda').setAttribute("onclick", "sma(true,'" + ID + "','" + V + "','" + P + "')");
    $D.g_ID('b_salir').setAttribute("onclick", "sma(false)");
    var v = $D.g_ID(ID);
    var c = 0;
    for (var i = 0; i < opciones.length; i++) {
        if (v.value.split(",")[c] == opciones[i].co_compag) {
            $D.g_ID("opt" + opciones[i].co_compag).checked = true;
            c++;
        }
    }

    $D.lock();
    $D.g_ID('BPM').style.display = "block";
    $D.g_ID("m_table_body").getElementsByTagName("TR")[0].getElementsByTagName("TD")[1].style.width = ($D.g_ID("m_table_body").getElementsByTagName("TR")[0].getElementsByTagName("TD")[1].offsetWidth + 10) + " px";
}

/**
 * (acc) : tipo de accion
 * (r) : input
 * (l) : label
 * (e) : estado
 * (b) : botom
 * */
function sma(acc, ID, V, P) {
    if (!acc) {
        $D.unlock();
        $D.g_ID("BPM").style.display = "none";
        return;
    }

    var inputs = $D.g_ID('m_table_body').getElementsByTagName("INPUT");
    var inputs2 = [];
    for (var i = 0; i < inputs.length; i++) {
        var input = inputs[i];
        if (input.checked) {
            inputs2[inputs2.length] = input.value;
        }
    }

    $D.g_ID(ID).value = inputs2.join(",");
    var ns = $D.g_ID(ID).value;
    var opts = options_gson[ID];
    var Ul = $D.g_ID(ID + "_" + V + "_L");
    var Ulx = "";
    var inx = 0;
    ns = (ns.length == "") ? "" : ns.split(",");
    for (var i = 0; i < ns.length; i++) {
        for (var o = 0; o < opts.length; o++) {
            if (opts[o].co_compag == ns[i]) {
                Ulx = Ulx + "<li>";
                Ulx = Ulx + "<b>-</b> " + opts[o].no_compag;
                Ulx = Ulx + "</li>";
                o = opts.length;
                inx = inx + 1;
            }
        }
    }
    Ulx = Ulx + "<li>";
    Ulx = Ulx + "<button onclick='verselectormultiple(\"" + ID + "\",\"" + V + "\",\"" + P + "\")' class='boton'>";
    Ulx = Ulx + (inx == 0 ? "Agregar" : "Editar");
    Ulx = Ulx + "</button>";
    Ulx = Ulx + "</li>";
    Ul.innerHTML = Ulx;
    $D.unlock();
    $D.g_ID("BPM").style.display = "none";
}

/**
 * ( r ) : id de registro
 * ( l ) : label
 * */
function creselectormultiple(r, l, b, rt) {

    var o = options_gson[r];
    var v = $D.g_ID(r).value.split(','); //array de ID's

    var n_s = "";
    if (rt != undefined) {
        n_s = "<ul style='margin: 2px;'>";
    }
    var lb = "";
    var c = 0;
    for (var i = 0; i < o.length; i++) {
        if (v[c] == o[i].co_compag) {
            if (rt != undefined) {
                n_s = n_s + "<li>" + o[i].no_compag + "</li>"
            } else {
                n_s = n_s + o[i].no_compag + ","
            }
            c++;
        }
    }

    if (rt != undefined) {
        n_s = n_s + "</ul>";
        lb = n_s;
    } else {
        if (n_s.substr(n_s.length - 1, n_s.length) == ',') {
            n_s = n_s.substr(0, n_s.length - 1);
        }

        lb = n_s;
        if (lb.length > 20)
            lb = lb.substr(0, 20) + "...";
    }


    var l_s = "";
    for (var j = 0; j < n_s.split(",").length; j++) {
        l_s = l_s + "- " + n_s.split(",")[j] + "<br>";
    }

    if ($D.g_ID(b) != null) {
        if ($D.g_ID(r).value == "") {
            $D.g_ID(b).setAttribute("src", "../img/note.png");
        } else {
            $D.g_ID(b).setAttribute("src", "../img/note_add.png");
            $D.g_ID(b).setAttribute("onmouseout", "hideTip(event)");
            $D.g_ID(b).setAttribute("onmouseover", "showTip(event, 'lista_select', '" + l_s + "', this)");
        }
    }

    if ($D.g_ID(l) != null) {
        $D.g_ID(l).innerHTML = lb;
    }
}

//TIPO 34:POPUP
function POPUP(u, ele, c, tit1, tit2) {
    var vp;
    u = u.replace("../wfl", "wf"); //[*]Esto debe de cambiar 
    var l = $D.g_ID(ele);
    if (l.tagName == "LABEL") {
        vp = u + "" + "&co_conpar_1=" + escape(l.getAttribute('valpag')) + "&co_conpar_2=" + escape(l.innerHTML) + "&co_conpar_3=" + u + "&co_conpad=" + c + "&popup=1&fe_solini=" + new Date().getTime();
    } else {
        vp = u + "" + "&co_conpar_1=" + escape(l.value) + "&co_conpar_2=" + escape(l.value) + "&co_conpar_3=" + u + "&co_conpad=" + c + "&popup=1&fe_solini=" + new Date().getTime();
    }

    $D.g_ID("popup_head").innerHTML = tit1 + "  >  <b>" + tit2 + "</b>";
    $D.g_ID("popup_body").onload = popup_resize;
    $D.g_ID("popup_body").setAttribute("ele", ele);
    $D.g_ID("popup_body").src = vp;
    $D.lock();
    $D.g_ID('popup').style.display = "block";
}

function vergeolocalizador(id, e, m, ra, p, t, t2) {
    if (p) {
        $D.g_ID("popup_body").setAttribute("ele", id);
        $D.g_ID("popup_head").innerHTML = t + " > <b>" + t2 + "</b>";
        $D.g_ID("popup_body").onload = popup_resizeB;
        $D.g_ID("popup_body").src = 'workflow2/google.jsp?google=' + $D.g_ID('v' + id).value + "&editable=" + e + "&modo=" + m + "&radio=" + ra;
        $D.lock();
        $D.g_ID('popup').style.display = "block";
    } else {
        window.open('google.jsp?google=' + $D.g_ID('v' + id).innerHTML + "&editable=" + e + "&modo=" + m + "&radio=" + ra, '_blank');
    }
}

/**
 * l label
 * r input value
 * e estado
 * m objeto principal
 * */
function VG_N(id, e, m) {
    var ng = options_gson["geo" + id];
    if (!e & ng.no_modo != "popup") {
//        console.log("veamos:" + "geocode.jsp?latitud=" + ng.no_latitud + "&longitud=" + ng.no_longitud + "&editable=" + e + "&modo=" + ng.no_modo + "&radio=" + ng.ca_radio + "&descripcion=" + ng.no_descripcion + "&tipo=" + ng.no_type);
        window.open("geocode.jsp?latitud=" + ng.no_latitud + "&longitud=" + ng.no_longitud + "&editable=" + e + "&modo=" + ng.no_modo + "&radio=" + ng.ca_radio + "&descripcion=" + ng.no_descripcion + "&tipo=" + ng.no_type, '_blank');
    } else {
        $D.g_ID("popup_body").setAttribute("ele", id);
        $D.g_ID("popup_head").innerHTML = "Editar Georeferencia";
        $D.g_ID("popup_body").onload = popup_resizeB;
//        console.log("vamos>>>;" + "workflow2/geocode.jsp?latitud=" + ng.no_latitud + "&longitud=" + ng.no_longitud + "&editable=" + e + "&modo=" + ng.no_modo + "&radio=" + ng.ca_radio + "&descripcion=" + ng.no_descripcion + "&tipo=" + ng.no_type);
        $D.g_ID("popup_body").src = "workflow2/geocode.jsp?latitud=" + ng.no_latitud + "&longitud=" + ng.no_longitud + "&editable=" + e + "&modo=" + ng.no_modo + "&radio=" + ng.ca_radio + "&descripcion=" + ng.no_descripcion + "&tipo=" + ng.no_type;
        $D.lock();
        $D.g_ID('popup').style.display = "block";
    }
}

function vergeolocalizador2(l, r, e, m, ra, p) {
    var m_tr;
    try {
        m_tr = r.getParent();
    } catch (e) {
        try {
            m_tr = r.parentNode;
        } catch (e2) {
        }
    }

    var im = m_tr.getElementsByTagName("INPUT")[0];
    var ReturnVal;
    if (p) {
        ReturnVal = window.showModalDialog('google.jsp?google=' + $D.g_ID(l).innerHTML + "&editable=" + e + "&modo=" + m + "&radio=" + ra, "argsVariable", "dialogWidth:800px; dialogHeight:500px; center:yes");
    }
    else {
        window.open('google.jsp?google=' + $D.g_ID(l).innerHTML + "&editable=" + e + "&modo=" + m + "&radio=" + ra, '_blank');
    }

    if (ReturnVal.toString() == 'undefined' | ReturnVal == undefined | ReturnVal.toString() == null) {
    } else if (ReturnVal.toString().length > 0) {
        $D.g_ID(l).innerHTML = ReturnVal;
        im.value = ReturnVal;
    }

}

function vergeolocalizadorA2(l, r, e, m) {
    var rVal = $D.g_ID(r).value;
    var no_latitud;
    var no_longitud;
    try {
        no_latitud = m.no_latitud;
    } catch (e) {
        no_latitud = "";
    }
    try {
        no_longitud = m.no_longitud;
    } catch (e) {
        no_longitud = "";
    }
    var ReturnVal;
    if (m.no_modo == "popup") {
        ReturnVal = window.showModalDialog("geocode.jsp?latitud=" + no_latitud + "&longitud=" + no_longitud + "&editable=" + e + "&modo=" + m.no_modo + "&radio=" + m.ca_radio + "&descripcion=" + m.no_descripcion + "&tipo=" + m.no_type, "argsVariable", "dialogWidth:800px; dialogHeight:500px; center:yes");
        if (ReturnVal.toString() == 'undefined' | ReturnVal == undefined | ReturnVal.toString() == null) {
        } else if (ReturnVal.toString().length > 0) {
            $D.g_ID(l).innerHTML = ReturnVal;
            $D.g_ID(r).value = ReturnVal;
            if (rVal.toString() != ReturnVal.toString()) {
                $D.g_ID(l).innerHTML = "Editar (existen datos modificados)";
            }
        }
    } else {
        window.open("geocode.jsp?latitud=" + no_latitud + "&longitud=" + no_longitud + "&editable=" + e + "&modo=" + m.no_modo + "&radio=" + m.ca_radio + "&descripcion=" + m.no_descripcion + "&tipo=" + m.no_type, '_blank');
    }
}

function documentoonkeypres(tabla, boton, co_pagina, vuelta, co_pagbot, id_frawor, co_conten, parametro, proces) {
    var inputs = $D.g_ID(tabla).getElementsByTagName("input");
    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].getAttribute("type") == "text" & inputs[i].className == "q input2") {
            if ($D.g_ID("l_" + inputs[i].id) != null) {
                var l_v = $D.g_ID("l_" + inputs[i].id);
                var n = $D.g_ID("" + inputs[i].id).getAttribute("onKeydown");
                inputs[i].setAttribute('onKeydown', n + ";if(event.keyCode==13){$D.g_ID('" + boton + "').onclick();return false;}");
            } else {
                inputs[i].setAttribute('onKeydown', "if(event.keyCode==13){$D.g_ID('" + boton + "').onclick();return false;}");
            }

        }
    }
}

function is_conpar(rp, con_par, v) {
    var b = false;
    for (var x = 0; x < rp.length; x = x + 2) {
        if (con_par == rp[x].toString()) {
            b = $D.n_E("input", "co_conpar_" + rp[x + 1].toString(), 'hidden', v);
            x = rp.length - 1;
        }
    }
    return b;
}

function update(C) {
    switch (C.tagName) {
        case "INPUT":
        {
            C.setAttribute("valpag", C.value);
            break;
        }
    }
}

function extractNumber(obj, decimalPlaces, allowNegative) {
    var temp = obj.value;
    // avoid changing things if already formatted correctly
    var reg0Str = '[0-9]*';
    if (decimalPlaces > 0) {
        reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
    }
    else if (decimalPlaces < 0) {
        reg0Str += '\\.?[0-9]*';
    }
    reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
    reg0Str = reg0Str + '$';
    var reg0 = new RegExp(reg0Str);
    if (reg0.test(temp))
        return true;
    // first replace all non numbers
    var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
    var reg1 = new RegExp(reg1Str, 'g');
    temp = temp.replace(reg1, '');
    if (allowNegative) {
// replace extra negative
        var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
        var reg2 = /-/g;
        temp = temp.replace(reg2, '');
        if (hasNegative)
            temp = '-' + temp;
    }
    if (decimalPlaces != 0) {
        var reg3 = /\./g;
        var reg3Array = reg3.exec(temp);
        if (reg3Array != null) {
// keep only first occurrence of .
// and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
            var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
            reg3Right = reg3Right.replace(reg3, '');
            reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
            temp = temp.substring(0, reg3Array.index) + '.' + reg3Right;
        }
    }
    obj.value = temp;
}

function blockNonNumbers(obj, e, allowDecimal, allowNegative) {
    var key;
    var isCtrl = false;
    var keychar;
    var reg;
    if (window.event) {
        key = e.keyCode;
        isCtrl = window.event.ctrlKey
    } else if (e.which) {
        key = e.which;
        isCtrl = e.ctrlKey;
    }
    if (isNaN(key))
        return true;
    keychar = String.fromCharCode(key);
    // check for backspace or delete, or if Ctrl was pressed
    if (key == 8 || isCtrl)
    {
        return true;
    }
    reg = /\d/;
    var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
    var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
    return isFirstN || isFirstD || reg.test(keychar);
}

function checkEmail(I, L) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($D.g_ID(I).value)) {
        $D.g_ID(L).innerHTML = "";
    } else {
        $D.g_ID(L).innerHTML = "<font color=red>E-mail no v&#225;lido</font>";
    }
}

//---------------POR EVALUAR EL USO
function tolower(e, event) {
    if (!(event.keyCode == '8' | event.keyCode == '35' | event.keyCode == '36' | event.keyCode == '37' | event.keyCode == '38' | event.keyCode == '39' | event.keyCode == '40' | event.keyCode == '16' | event.keyCode == '17')) {
        e.value = e.value.toLowerCase();
    }
}

//---------------POR EVALUAR EL USO
function rankana(o) {
    var m_td = null;
    try {
        m_td = o.getParent();
    } catch (e) {
        m_td = o.parentNode;
    }
    try {
        m_td = m_td.getParent();
    } catch (e) {
        m_td = m_td.parentNode;
    }
    m_td = m_td.cells[0];
    var m_inputs = getElementsByClassName(m_td, 'q');
    var m_ele = m_inputs[0]
    return m_ele;
}

/**
 *Metodo para lanzar hacia un nuevo contenedor
 **/
function iqaro_R(co_usuari, li_botpar, co_pagina, co_vuelta, co_pagbot, id_frawor, co_conten, co_conori, il_proces, ti_conten, co_conpad, il_confirm, il_authen, no_confir, no_target) {
    $D.wait();
    var accion = new Action({
        co_usuari: co_usuari,
        li_botpar: li_botpar,
        co_pagina: co_pagina,
        co_vuelta: co_vuelta,
        co_pagbot: co_pagbot,
        id_frawor: id_frawor,
        co_condes: co_conten,
        co_conten: co_conori,
        ti_conten: ti_conten,
        no_target: no_target,
        is_propag: il_proces,
        il_confirm: il_confirm,
        il_authen: il_authen,
        no_confir: no_confir
    });
    if (accion.il_confirm) {
        $D.g_ID("confirmacion_boton_si").onclick = function () {
            iqaro_R(co_usuari, li_botpar, co_pagina, co_vuelta, co_pagbot, id_frawor, co_conten, co_conori, il_proces, ti_conten, co_conpad, false, il_authen, no_confir, no_target);
            $D.cancel();
        };
        $D.wakeup();
        $D.confirm(accion.no_confir);
        $D.g_ID("confirmacion_boton_no").focus();
        $D.g_ID("confirmacion_boton_si").focus();
        return;
    } else if (accion.il_authen) {
        $D.g_ID("block_pane4_message_error").innerHTML = "";
        $D.g_ID("block_pane4_password").value = "";
        $D.g_ID('block_pane4_password').setAttribute('onKeydown', "if(event.keyCode==13){$D.g_ID('block_pane4_boton_aceptar').onclick();return false;}");
        $D.g_ID("block_pane4_boton_cancelar").onclick = function () {
            $D.wakeup();
            $D.cancel();
            $D.deauthen();
        };
        $D.g_ID("block_pane4_boton_aceptar").onclick = function () {
            var pass = hex_md5($D.g_ID("block_pane4_password").value);
            var proces = $D.getTEXT("wfp?xact=10&p_pw_usuari=" + pass + "&p_co_usulog=" + accion.co_usuari).trim();
            if (proces == 't' | proces == 'true') {
                $D.deauthen();
                iqaro_R(co_usuari, li_botpar, co_pagina, co_vuelta, co_pagbot, id_frawor, co_conten, co_conori, il_proces, ti_conten, co_conpad, il_confirm, false, no_confir, no_target);
            } else {
                $D.g_ID("block_pane4_message_error").innerHTML = "Password incorrecto";
                $D.g_ID("block_pane4_password").focus();
            }
        };
        $D.wakeup();
        $D.cancel();
        $D.authen();
        $D.g_ID("block_pane4_password").focus();
        return;
    }


    var m_tr = $D.g_ID("t" + accion.co_pagina);
    accion.addInput($D.n_E('input', 'co_pagina', 'hidden', accion.co_pagina));
    accion.addInput($D.n_E('input', 'co_conten', 'hidden', accion.co_condes));
    if (accion.ti_conten == "wg2")
        accion.addInput($D.n_E('input', 'co_congeo', 'hidden', accion.co_condes));
    accion.addInput($D.n_E('input', 'co_conori', 'hidden', accion.co_conten));
    accion.addInput($D.n_E('input', 'item', 'hidden', $D.g_ID("item").value));
    if (co_conpad != null | co_conpad != undefined | co_conpad != '')
        accion.addInput($D.n_E('input', 'co_conpad', 'hidden', co_conpad));
    accion.addInput($D.n_E('input', 'co_pagbot', 'hidden', accion.co_pagbot));
    accion.addInput($D.n_E('input', 'id_fraant', 'hidden', accion.id_frawor));
    accion.addInput($D.n_E('input', 'cabecera', 'hidden', "false"));
    accion = iqaro_tabla_loadinputs(accion, getElementsByClassName(m_tr, "q"));
    accion.setIs_compus(accion.getLi_compus().length > 0 ? true : false);
    sub_accion(accion);
}

function sub_accion(accion) {
    if (accion.getIs_compus()) {
        var $O = null;
        for (var i = 0; i < accion.getLi_compus().length; i++) {
            if (!accion.getLi_compus()[i].is_process) {
                $O = accion.getLi_compus()[i];
                i = accion.getLi_compus().length - 1;
            }
        }

        if ($O != null) {
            var p = $D.g_ID($O.id_valore);
            var x = null;
            try {
                x = p.contentWindow.document.getElementById('va_regist_file').getAttribute('nuevo');
            } catch (e) {
                x = false;
            }

            if (x == 'true') {
                if (p.contentWindow.document.getElementById("va_regist_file").value == "") {
                    $O.no_valore = '';
                    if ($O.getCo_conpar())
                        $O.getCo_conpar().setAttribute("value", $O.no_valore);
                    if ($O.getVa_pagreg())
                        $O.getVa_pagreg().setAttribute("value", $O.no_valore);
                    if ($O.getCo_conpar())
                        accion.addInput($O.getCo_conpar());
                    if ($O.getVa_pagreg())
                        accion.addInput($O.getVa_pagreg());
                    $O.is_process = true;
                    setTimeout(function () {
                        sub_accion(accion);
                    }, 1000);
                } else {
                    if ($O.is_submit) {
                        var R = p.contentWindow.document.getElementById("NAME_FILE").getAttribute("name");
                        if (R == undefined | R == "")
                            setTimeout(function () {
                                sub_accion(accion);
                            }, 1000);
                        else {
                            //si encontro data
                            $O.no_valore = R;
                            if ($O.getCo_conpar())
                                $O.getCo_conpar().setAttribute("value", $O.no_valore);
                            if ($O.getVa_pagreg())
                                $O.getVa_pagreg().setAttribute("value", $O.no_valore);
                            if ($O.getCo_conpar())
                                accion.addInput($O.getCo_conpar());
                            if ($O.getVa_pagreg())
                                accion.addInput($O.getVa_pagreg());
                            $O.is_process = true;
                            setTimeout(function () {
                                sub_accion(accion);
                            }, 10000);
                        }
                    } else {
                        $D.wait_msg(p.contentWindow.document.getElementById("va_regist_file").value);
                        p.contentWindow.document.getElementById("form_data").submit();
                        $O.is_submit = true;
                        setTimeout(function () {
                            sub_accion(accion);
                        }, 1000);
                        return;
                    }
                }
            } else {
                var R = null;
                try {
                    R = p.contentWindow.document.getElementById("NAME_FILE").getAttribute("name");
                } catch (e) {
                    R = "";
                }

                if (R == undefined | R == "" | R == null)
                    setTimeout(function () {
                        sub_accion(accion);
                    }, 1000);
                else {
                    $O.no_valore = R;
                    if ($O.getCo_conpar())
                        $O.getCo_conpar().setAttribute("value", $O.no_valore);
                    if ($O.getVa_pagreg())
                        $O.getVa_pagreg().setAttribute("value", $O.no_valore);
                    if ($O.getCo_conpar())
                        accion.addInput($O.getCo_conpar());
                    if ($O.getVa_pagreg())
                        accion.addInput($O.getVa_pagreg());
                    $O.is_process = true;
                    setTimeout(function () {
                        sub_accion(accion);
                    }, 1000);
                }
            }
        } else {
            accion.setIs_compus(false);
            setTimeout(function () {
                sub_accion(accion);
            }, 1000);
        }
    } else {
        $D.wait_msg("Operaci&oacute;n en proceso...");
        if (accion.getIs_propag()) {
            if (accion.getIs_submit()) {
                var proces = $D.g_ID("pagreg").contentWindow.document.getElementsByTagName("BODY")[0];
                if (($D.g_ID("pagreg").contentWindow.document.getElementById("form_data") == undefined | $D.g_ID("pagreg").contentWindow.document.getElementById("form_data") == null) & (proces != undefined | proces != null)) {
                    if (proces.innerHTML.length > 0) {
                        if (proces.innerHTML == "OK" & (accion.ti_conten == "wf" | accion.ti_conten == "wf2" | accion.ti_conten == "wg2")) {
                            var f;
                            if (accion.ti_conten == "wf") {
                                f = $D.g_ID("m_f");
                                f.name = "m_f";
                            } else if (accion.ti_conten == "wf2") {
                                f = $D.g_ID("m_f");
                                f.name = "m_f";
                            } else if (accion.ti_conten == "wg2") {
                                f = $D.g_ID("m_f");
                                f.name = "m_f";
                            } else {
                                f = $D.g_ID("m_fl");
                                f.name = "m_fl";
                            }

                            f.action = $D.base() + "/" + accion.ti_conten;
                            f.method = 'POST';
                            f.innerHTML = "";
                            accion.addInput($D.n_E('input', 'fe_solini', 'hidden', new Date().getTime()));
                            for (var i = 0; i < accion.getLi_inputs().length; i++) {
                                f.appendChild(accion.getLi_inputs()[i]);
                            }
                            if (accion.no_target == null)
                                f.removeAttribute("target")
                            else {
                                f.setAttribute("target", accion.no_target);
                                $D.wakeup(false);
                            }
                            f.submit();
                        } else if (proces.innerHTML == "OK" & accion.ti_conten == "wfl") {
                            try {
                                var proces2 = $D.getJSONE($D.base() + "/wfp?xact=13&id_frawor=" + accion.id_frawor + "&co_conten=" + accion.co_conten);
                                if (proces2 == undefined) {
                                    proces2 = $D.getJSON($D.base() + "/wfp?xact=13&id_frawor=" + accion.id_frawor + "&co_conten=" + accion.co_conten);
                                }
                                console.log("Resultado de proceso wfl:" + proces2);
                                parent.parent_close_popup(proces2);
                            } catch (ep) {
                                console.log("Datos del error: " + ep);
                            }
                        } else {
                            $D.g_ID("block_pane2").style.display = "none";
                            mensaje(null, proces.innerHTML, null, null, 1)
                        }
                    } else {
                        setTimeout(function () {
                            sub_accion(accion);
                        }, 1000);
                    }
                } else {
                    setTimeout(function () {
                        sub_accion(accion);
                    }, 1000);
                }
            } else {
                var wfp_fr = $D.g_ID("pagreg");
                var f_wfp = wfp_fr.contentWindow.document.getElementById("form_data");
                if (f_wfp != null && f_wfp != undefined) {
                    wfp_fr.contentWindow.document.body.removeChild(f_wfp);
                }

                f_wfp = wfp_fr.contentWindow.document.createElement("form");
                wfp_fr.contentWindow.document.body.appendChild(f_wfp);
                f_wfp.id = "form_data";
                f_wfp.action = $D.base() + "/wfp?xact=5&propag=1&borrar=1&id_frawor=" + accion.id_frawor;
                f_wfp.method = 'POST';
                f_wfp.innerHTML = "";
                for (var i = 0; i < accion.getLi_inputs().length; i++) {
                    if (!(accion.getLi_inputs()[i].getAttribute("name").indexOf("va_vapreg") == 0))
                        f_wfp.appendChild(accion.getLi_inputs()[i]);
                }
                f_wfp.submit();
                accion.setIs_submit(true);
                setTimeout(function () {
                    sub_accion(accion);
                }, 1000);
            }
        } else {
            var f;
            if (accion.ti_conten == "wf") {
                f = $D.g_ID("m_f");
                f.name = "m_f";
            } else if (accion.ti_conten == "wf2") {
                f = $D.g_ID("m_f");
                f.name = "m_f";
            } else if (accion.ti_conten == "wg2") {
                f = $D.g_ID("m_f");
                f.name = "m_f";
            } else {
                f = $D.g_ID("m_fl");
                f.name = "m_fl";
            }

            f.action = $D.base() + "/" + accion.ti_conten;
            f.method = 'POST';
            f.innerHTML = "";
            accion.addInput($D.n_E('input', 'fe_solini', 'hidden', new Date().getTime()));
            for (var i = 0; i < accion.getLi_inputs().length; i++) {
                f.appendChild(accion.getLi_inputs()[i]);
            }

            if (accion.no_target == null)
                f.removeAttribute("target")
            else {
                f.setAttribute("target", accion.no_target);
                $D.wakeup(false);
            }
            f.submit();
        }
    }
}

function iqaro_tabla_loadinputs(accion, $si) {
    for (var n_ = 0; n_ < $si.length; n_++) {
        var $c = $si[n_];
        var z;
        var ts = $c.id.replace("v" + accion.co_pagina + "_", "");
        var reg_par = accion.li_botpar.split(",");
        if (ts.split("_")[0] == accion.co_vuelta) {
            if ($c.tagName == "INPUT") {
                accion.addInput($D.n_E('input', $c.id.replace("v", "va_regist_"), 'hidden', $c.value));
                for (var x = 0; x < reg_par.length; x = x + 2) {
                    if (($c.id).split("_")[2] == reg_par[x].toString()) {
                        accion.addInput($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.value));
                        x = reg_par.length - 1;
                    }
                }
            } else if ($c.tagName == "LABEL") {
                accion.addInput($D.n_E('input', $c.id.replace("v", "va_regist_"), 'hidden', $c.getAttribute("valpag")));
                for (var x = 0; x < reg_par.length; x = x + 2) {
                    if (($c.id).split("_")[2] == reg_par[x].toString()) {
                        accion.addInput($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.getAttribute("valpag")));
                        x = reg_par.length - 1;
                    }
                }
            } else if ($c.tagName == "SELECT") {
                if ($c.options.length == 0) {
                    accion.addInput($D.n_E('input', $c.id.replace("v", "va_regist_"), 'hidden', ''));
                } else {
                    accion.addInput($D.n_E('input', $c.id.replace("v", "va_regist_"), 'hidden', $c.options[$c.selectedIndex].value));
                }

                if ($c.options.length == 0) {
                    for (var x = 0; x < reg_par.length; x = x + 2) {
                        if (($c.id).split("_")[2] == reg_par[x].toString()) {
                            accion.addInput($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', ''));
                            x = reg_par.length - 1;
                        }
                    }
                } else {
                    for (var x = 0; x < reg_par.length; x = x + 2) {
                        if (($c.id).split("_")[2] == reg_par[x].toString()) {
                            accion.addInput($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.options[$c.selectedIndex].value));
                            x = reg_par.length - 1;
                        }
                    }
                }
            } else if ($c.tagName == "TEXTAREA") {
                accion.addInput($D.n_E('input', $c.id.replace("v", "va_regist_"), 'hidden', $c.value.replace(/\r\n/g, "&0A")));
                for (var x = 0; x < reg_par.length; x = x + 2) {
                    if (($c.id).split("_")[2] == reg_par[x].toString()) {
                        accion.addInput($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.value));
                        x = reg_par.length - 1;
                    }
                }
            } else if ($c.tagName == "IFRAME") {
                var p = $D.g_ID($c.id);
                var ps = p.contentWindow.document.getElementById("NAME_FILE");
                if (ps == null | ps == undefined) {
                    try {
                        accion.addInput($D.n_E('input', $c.id.replace("v", "va_regist_"), 'hidden', p.contentWindow.editor.getValue()));
                        for (var x = 0; x < reg_par.length; x = x + 2) {
                            if (($c.id).split("_")[2] == reg_par[x].toString()) {
                                accion.addInput($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', p.contentWindow.editor.getValue()));
                                x = reg_par.length - 1;
                            }
                        }
                    } catch (e) {
                    }
                } else if (ps.getAttribute("estado") == "UNCOMPLETE") {
                    var oc = new Oc({
                        id_valore: $c.id
                    });
                    oc.setVa_pagreg($D.n_E('input', $c.id.replace("v", "va_regist_"), 'hidden', ''));
                    for (var x = 0; x < reg_par.length; x = x + 2) {
                        if (($c.id).split("_")[2] == reg_par[x].toString()) {
                            oc.setCo_conpar($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', ''))
                            x = reg_par.length - 1;
                        }
                    }
                    accion.addCompus(oc);
                } else {
                    accion.addInput($D.n_E('input', $c.id.replace("v", "va_regist_"), 'hidden', ps.getAttribute("name")));
                    for (var x = 0; x < reg_par.length; x = x + 2) {
                        if (($c.id).split("_")[2] == reg_par[x].toString()) {
                            accion.addInput($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', ps.getAttribute("name")));
                            x = reg_par.length - 1;
                        }
                    }
                }
            }
        }
    }
    return accion;
}

/**
 *
 **/

function iqaro_tabla_loadinputs2(accion, $si) {
    for (var n_ = 0; n_ < $si.length; n_++) {
        var $c = $si[n_];
        var z;
        var ts = $c.id.replace("v" + accion.co_pagina + "_", "");
        var reg_par = accion.li_botpar.split(",");
        if ($c.id.split("_").length == 3) {
            $c.id = $c.id.split("_")[2];
        }

        if ($c.tagName == "INPUT") {
            accion.addInput($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + accion.co_vuelta + "_" + $c.id, 'hidden', $c.value));
            for (var x = 0; x < reg_par.length; x = x + 2) {
                if (($c.id) == reg_par[x].toString()) {
                    accion.addInput($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.value));
                    x = reg_par.length - 1;
                }
            }
        } else if ($c.tagName == "LABEL") {
            accion.addInput($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + accion.co_vuelta + "_" + $c.id, 'hidden', ($c.getAttribute("v") == undefined) ? $c.innerHTML : $c.getAttribute("v")));
            for (var x = 0; x < reg_par.length; x = x + 2) {
                if (($c.id) == reg_par[x].toString()) {
                    accion.addInput($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', ($c.getAttribute("v") == undefined) ? $c.innerHTML : $c.getAttribute("v")));
                    x = reg_par.length - 1;
                }
            }
        } else if ($c.tagName == "SELECT") {
            if ($c.options.length == 0) {
                accion.addInput($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + accion.co_vuelta + "_" + $c.id, 'hidden', ''));
            } else {
                accion.addInput($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + accion.co_vuelta + "_" + $c.id, 'hidden', $c.options[$c.selectedIndex].value));
            }

            if ($c.options.length == 0) {
                for (var x = 0; x < reg_par.length; x = x + 2) {
                    if (($c.id) == reg_par[x].toString()) {
                        accion.addInput($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', ''));
                        x = reg_par.length - 1;
                    }
                }
            } else {
                for (var x = 0; x < reg_par.length; x = x + 2) {
                    if (($c.id) == reg_par[x].toString()) {
                        accion.addInput($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.options[$c.selectedIndex].value));
                        x = reg_par.length - 1;
                    }
                }
            }
        } else if ($c.tagName == "TEXTAREA") {
            accion.addInput($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + accion.co_vuelta + "_" + $c.id, 'hidden', $c.value.replace(/\r\n/g, "&0A")));
            for (var x = 0; x < reg_par.length; x = x + 2) {
                if (($c.id) == reg_par[x].toString()) {
                    accion.addInput($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.value));
                    x = reg_par.length - 1;
                }
            }
        } else if ($c.tagName == "IFRAME") {
            var p = $D.g_ID($c.id);
            var ps = p.contentWindow.document.getElementById("NAME_FILE");
            if (ps == null | ps == undefined) {
                try {
                    accion.addInput($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + accion.co_vuelta + "_" + $c.id, 'hidden', p.contentWindow.editor.getValue()));
                    for (var x = 0; x < reg_par.length; x = x + 2) {
                        if (($c.id) == reg_par[x].toString()) {
                            accion.addInput($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', p.contentWindow.editor.getValue()));
                            x = reg_par.length - 1;
                        }
                    }
                } catch (e) {
                }
            } else if (ps.getAttribute("estado") == "UNCOMPLETE") {
                var oc = new Oc({
                    id_valore: $c.id
                });
                oc.setVa_pagreg($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + accion.co_vuelta + "_" + $c.id, 'hidden', ''));
                for (var x = 0; x < reg_par.length; x = x + 2) {
                    if (($c.id) == reg_par[x].toString()) {
                        oc.setCo_conpar($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', ''))
                        x = reg_par.length - 1;
                    }
                }
                accion.addCompus(oc);
            } else {
                accion.addInput($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + accion.co_vuelta + "_" + $c.id, 'hidden', ps.getAttribute("name")));
                for (var x = 0; x < reg_par.length; x = x + 2) {
                    if (($c.id) == reg_par[x].toString()) {
                        accion.addInput($D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', ps.getAttribute("name")));
                        x = reg_par.length - 1;
                    }
                }
            }
        }
    }
    return accion;
}


function iqaro_tabla_tr(regpar, id_pag, v, boton, id_frawor, co_conten, wf, co_conpad, target) {

    var reg_par = regpar.split(",");
    boton = $D.g_ID(boton);
    var m_tr;
    try {
        m_tr = boton.getParent();
    } catch (e) {
        try {
            m_tr = boton.parentNode;
        } catch (e2) {
        }
    }
    try {
        m_tr = m_tr.getParent();
    } catch (e2) {
        m_tr = m_tr.parentNode;
    }

    var f;
    if (wf == "wf" | wf == "wf2") {
        f = $D.g_ID("m_f");
    } else {
        f = $D.g_ID("m_fl");
    }

    f.action = $D.base() + "/" + wf;
    f.method = 'POST';
    f.innerHTML = "";
    var co_c = $D.n_E('input', 'co_conten', 'hidden', co_conten);
    f.appendChild(co_c);
    var cabecera = $D.n_E('input', 'cabecera', 'hidden', "false");
    f.appendChild(cabecera);
    if (co_conpad != null | co_conpad != undefined | co_conpad == '') {
        var co_c = $D.n_E('input', 'co_conpad', 'hidden', co_conpad);
        f.appendChild(co_c);
    }

    var id_fa = $D.n_E('input', 'id_fraant', 'hidden', id_frawor);
    f.appendChild(id_fa);
    var $si = getElementsByClassName(m_tr, "s");
    for (var n_ = 0; n_ < $si.length; n_++) {
        var $c = $si[n_];
        var ra = "1";
        if ($c.id.indexOf("_") == -1) {
            ra = $c.id;
        } else {
            ra = $c.id.split("_")[2];
        }

        var n_i = $D.n_E("input", "va_regist_" + id_pag + "_" + v + "_" + ra, 'hidden', null); //$D.n_E('input');
        if ($c.tagName == "INPUT") {
            n_i.value = $c.value;
            f.appendChild(n_i);
        } else if ($c.tagName == "LABEL") {
            try {
                if ($c.getAttribute("v") != null | $c.getAttribute("v") != undefined) {
                    n_i.value = $c.getAttribute("v");
                } else {
                    n_i.value = $c.innerHTML;
                }
            } catch (e) {
                n_i.value = $c.innerHTML;
            }
            f.appendChild(n_i);
        } else if ($c.tagName == "SELECT") {
            if ($c.options.length == 0) {
                n_i.value = "";
            }
            else {
                n_i.value = $c.value;
            }
            f.appendChild(n_i);
        } else if ($c.tagName == "TEXTAREA") {
            n_i.value = $c.value;
            f.appendChild(n_i);
        } else if ($c.tagName == "IFRAME") {
            var p = $D.g_ID($c.id);
            var ps = p.contentWindow.document.getElementById("NAME_FILE");
            n_i.value = ps.getAttribute("name");
            f.appendChild(n_i);
        }
    }

    var $si2 = getElementsByClassName(m_tr, "q");
    for (var n_ = 0; n_ < $si2.length; n_++) {
        var $c = $si2[n_];
        var sid = "1";
        if ($c.id.indexOf("_") == -1) {
            sid = $c.id;
        }
        else {
            sid = $c.id.split("_")[2];
        }

        var z;
        if ($c.tagName == "INPUT") {
            z = is_conpar(reg_par, (sid), $c.value);
            if (z != false)
                f.appendChild(z);
        } else if ($c.tagName == "LABEL") {
            try {
                if ($c.getAttribute("v") != null | $c.getAttribute("v") != undefined) {
                    z = is_conpar(reg_par, (sid), $c.getAttribute("v"));
                } else {
                    z = is_conpar(reg_par, (sid), $c.innerHTML);
                }
            } catch (e) {
                z = is_conpar(reg_par, (sid), $c.innerHTML);
            }
            if (z != false)
                f.appendChild(z);
        } else if ($c.tagName == "SELECT") {
            z = is_conpar(reg_par, (sid), ($c.options.length > 0) ? $c.options[$c.selectedIndex].value : '');
            if (z != false)
                f.appendChild(z);
        } else if ($c.tagName == "TEXTAREA") {
            z = is_conpar(reg_par, (sid), $c.value);
            if (z != false)
                f.appendChild(z);
        } else if ($c.tagName == "IFRAME") {
            var p = $D.g_ID("va_regist_" + id_pag + "_" + v + "_" + $c.id.split("_")[1]); //Elemento aun por revisar
            var ps = p.contentWindow.document.getElementById("NAME_FILE");
            z = is_conpar(reg_par, (sid), ps.getAttribute("name"));
            if (z != false)
                f.appendChild(z);
        }
    }

    if (target != null) {
        f.setAttribute("target", target);
    }
    else {
        f.removeAttribute("target");
    }
    f.submit();
}

function iqaro_tabla_tr_proces(regpar, id_pag, v, boton, id_frawor, co_conten, co_conori, p_co_pagbot, wf, co_conpad, target) {
    var reg_par = regpar.split(",");
    boton = $D.g_ID(boton);
    var m_tr;
    try {
        m_tr = boton.getParent();
    } catch (e) {
        try {
            m_tr = boton.parentNode;
        } catch (e2) {
        }
    }
    try {
        m_tr = m_tr.getParent();
    } catch (e2) {
        m_tr = m_tr.parentNode;
    }

    var f;
    if (wf == "wf") {
        f = $D.g_ID("m_f");
        f.name = "m_f";
    } else if (wf == "wf2") {
        f = $D.g_ID("m_f");
        f.name = "m_f";
    } else {
        f = $D.g_ID("m_fl");
        f.name = "m_fl";
    }
    f.action = $D.base() + "/" + wf;
    f.method = 'POST';
    f.innerHTML = "";
    wfp_fr = $D.g_ID("pagreg");
    var f_wfp = wfp_fr.contentWindow.document.getElementById("form_data");
    if (f_wfp != null && f_wfp != undefined) {
        wfp_fr.contentWindow.document.body.removeChild(f_wfp);
    }
    f_wfp = wfp_fr.contentWindow.document.createElement("form");
    wfp_fr.contentWindow.document.body.appendChild(f_wfp);
    f_wfp.id = "form_data";
    f_wfp.setAttribute("method", "post");
    f_wfp = wfp_fr.contentWindow.document.getElementById("form_data");
    f_wfp.action = $D.base() + "/wfp?xact=5&propag=1&borrar=1&id_frawor=" + id_frawor;
    var co_p = $D.n_E('input', "co_pagina", 'hidden', id_pag);
    f.appendChild(co_p);
    co_p = $D.n_E('input', "co_pagina", 'hidden', id_pag);
    f_wfp.appendChild(co_p);
    var co_c = $D.n_E('input', "co_conten", 'hidden', co_conten);
    f.appendChild(co_c);
    co_c = $D.n_E('input', "co_conten", 'hidden', co_conten);
    f_wfp.appendChild(co_c);
    var co_co = $D.n_E('input', "co_conori", 'hidden', co_conori);
    f.appendChild(co_co);
    co_co = $D.n_E('input', "co_conori", 'hidden', co_conori);
    f_wfp.appendChild(co_co);
    var co_pb = $D.n_E('input', 'co_pagbot', 'hidden', p_co_pagbot);
    f.appendChild(co_pb);
    co_pb = $D.n_E('input', 'co_pagbot', 'hidden', p_co_pagbot);
    f_wfp.appendChild(co_pb);
    var id_tf = $D.n_E('input', 'id_fraant', 'hidden', id_frawor);
    f.appendChild(id_tf);
    var cabecera = $D.n_E('input', 'cabecera', 'hidden', "false");
    f.appendChild(cabecera);
    var va_reg;
    var $si = getElementsByClassName(m_tr, "s");
    for (var n_ = 0; n_ < $si.length; n_++) {
        var $c = $si[n_];
        var sid = "1";
        if ($c.id.indexOf("_") == -1) {
            sid = $c.id;
        }
        else {
            sid = $c.id.split("_")[2];
        }

        if ($c.tagName == "INPUT") {
            va_reg = $D.n_E('input', "va_regist_" + id_pag + "_" + v + "_" + sid, 'hidden', $c.value);
            f_wfp.appendChild(va_reg);
        } else if ($c.tagName == "LABEL") {
            try {
                if ($c.getAttribute("v") != null | $c.getAttribute("v") != undefined) {
                    va_reg = $D.n_E('input', "va_regist_" + id_pag + "_" + v + "_" + sid, 'hidden', $c.getAttribute("v"));
                    f_wfp.appendChild(va_reg);
                } else {
                    va_reg = $D.n_E('input', "va_regist_" + id_pag + "_" + v + "_" + sid, 'hidden', $c.innerHTML);
                    f_wfp.appendChild(va_reg);
                }
            } catch (e) {
                va_reg = $D.n_E('input', "va_regist_" + id_pag + "_" + v + "_" + sid, 'hidden', $c.innerHTML);
                f_wfp.appendChild(va_reg);
            }
        } else if ($c.tagName == "SELECT") {
            if ($c.options.length == 0) {
                va_reg = $D.n_E('input', sid, 'hidden', '');
                f_wfp.appendChild(va_reg);
            } else {
                va_reg = $D.n_E('input', "va_regist_" + id_pag + "_" + v + "_" + sid, 'hidden', $c.options[$c.selectedIndex].value);
                f_wfp.appendChild(va_reg);
            }
        } else if ($c.tagName == "TEXTAREA") {
            va_reg = $D.n_E('input', "va_regist_" + id_pag + "_" + v + "_" + sid, 'hidden', $c.value.replace(/\r\n/g, "&0A"));
            f_wfp.appendChild(va_reg);
        } else if ($c.tagName == "IFRAME") {
            var p = $D.g_ID("va_regist_" + id_pag + "_" + v + "_" + sid);
            var ps = p.contentWindow.document.getElementById("NAME_FILE");
            va_reg = $D.n_E('input', "va_regist_" + id_pag + "_" + v + "_" + sid, 'hidden', ps.getAttribute("name"));
            f_wfp.appendChild(va_reg);
        }
    }

    var $si2 = getElementsByClassName(m_tr, "q");
    for (var n_ = 0; n_ < $si2.length; n_++) {
        var $c = $si2[n_];
        var sid = "1";
        if ($c.id.indexOf("_") == -1) {
            sid = $c.id;
        }
        else {
            sid = $c.id.split("_")[2];
        }

        var z;
        if ($c.tagName == "INPUT") {
            for (var x = 0; x < reg_par.length; x = x + 2) {
                if ((sid) == reg_par[x].toString()) {
                    va_reg = $D.n_E('input', "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.value);
                    f_wfp.appendChild(va_reg);
                    z = $D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.value);
                    f.appendChild(z);
                    x = reg_par.length - 1;
                }
            }
        } else if ($c.tagName == "LABEL") {
            for (var x = 0; x < reg_par.length; x = x + 2) {
                if ((sid) == reg_par[x].toString()) {
                    try {
                        if ($c.getAttribute("v") != null | $c.getAttribute("v") != undefined) {
                            va_reg = $D.n_E('input', "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.getAttribute("v"));
                            f_wfp.appendChild(va_reg);
                            z = $D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.getAttribute("v"));
                        } else {
                            va_reg = $D.n_E('input', "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.innerHTML);
                            f_wfp.appendChild(va_reg);
                            z = $D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.innerHTML);
                        }
                    } catch (e) {
                        va_reg = $D.n_E('input', "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.innerHTML);
                        f_wfp.appendChild(va_reg);
                        z = $D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.innerHTML);
                    }

                    f.appendChild(z);
                    x = reg_par.length - 1;
                }
            }
        } else if ($c.tagName == "SELECT") {
            if ($c.options.length == 0) {
                for (var x = 0; x < reg_par.length; x = x + 2) {
                    if ((sid) == reg_par[x].toString()) {
                        va_reg = $D.n_E('input', "co_conpar_" + reg_par[x + 1].toString(), 'hidden', '');
                        f_wfp.appendChild(va_reg);
                        z = $D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', '');
                        f.appendChild(z);
                        x = reg_par.length - 1;
                    }
                }
            } else {
                for (var x = 0; x < reg_par.length; x = x + 2) {
                    if ((sid) == reg_par[x].toString()) {
                        va_reg = $D.n_E('input', "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.options[$c.selectedIndex].value);
                        f_wfp.appendChild(va_reg);
                        z = $D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.options[$c.selectedIndex].value);
                        f.appendChild(z);
                        x = reg_par.length - 1;
                    }
                }
            }
        } else if ($c.tagName == "TEXTAREA") {
            for (var x = 0; x < reg_par.length; x = x + 2) {
                if ((sid) == reg_par[x].toString()) {
                    va_reg = $D.n_E('input', "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.value.replace(/\r\n/g, "&0A"));
                    f_wfp.appendChild(va_reg);
                    z = $D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', $c.value);
                    f.appendChild(z);
                    x = reg_par.length - 1;
                }
            }
        } else if ($c.tagName == "IFRAME") {
            var p = $D.g_ID($c.id);
            var ps = p.contentWindow.document.getElementById("NAME_FILE");
            for (var x = 0; x < reg_par.length; x = x + 2) {
                if ((sid) == reg_par[x].toString()) {
                    va_reg = $D.n_E('input', "co_conpar_" + reg_par[x + 1].toString(), 'hidden', escape(ps.getAttribute("name")));
                    f_wfp.appendChild(va_reg);
                    z = $D.n_E("input", "co_conpar_" + reg_par[x + 1].toString(), 'hidden', ps.getAttribute("name"));
                    f.appendChild(z);
                    x = reg_par.length - 1;
                }
            }
        }
    }

    $D.g_ID("modalDialogPageBackground").style.display = "block";
    $D.g_ID("block_pane2").style.display = "block";
    wfp_fr.addEventListener('load', function () {
        var frame = $D.g_ID("pagreg");
        var proces = frame.contentWindow.document.getElementsByTagName("BODY")[0].innerHTML;
        if (frame.contentWindow.document.getElementById("form_data") == null) {
            if (proces == 'OK') {
                if (wf == "wf") {
                    f.submit();
                } else if (wf == "wf2") {
                    f.submit();
                } else {
                    var proces2 = $D.getJSONE($D.base() + "/wfp?xact=13&id_frawor=" + id_frawor + "&co_conten=" + co_conori);
                    if (proces2 == undefined) {
                        proces2 = $D.getJSON($D.base() + "/wfp?xact=13&id_frawor=" + id_frawor + "&co_conten=" + co_conori);
                    }
                    window.returnValue = proces2;
                    window.close();
                }
            } else {
                $D.g_ID("block_pane2").style.display = "none";
                mensaje(null, proces, null, null, 1)
            }
        }
    }, false);
    f_wfp.submit();
}

function iqaro_T(co_usuari, li_botpar, co_pagina, co_vuelta, co_pagbot, id_frawor, co_conten, co_conori, il_proces, ti_conten, co_conpad, il_confirm, il_authen, no_confir, no_target) {
    $D.wait();
    var accion = new Action({
        co_usuari: co_usuari,
        li_botpar: li_botpar,
        co_pagina: co_pagina,
        co_vuelta: co_vuelta,
        co_pagbot: co_pagbot,
        id_frawor: id_frawor,
        co_condes: co_conten,
        co_conten: co_conori,
        ti_conten: ti_conten,
        no_target: no_target,
        is_propag: il_proces,
        il_confirm: il_confirm,
        il_authen: il_authen,
        no_confir: no_confir
    });
    if (accion.il_confirm) {
        $D.g_ID("confirmacion_boton_si").onclick = function () {
            iqaro_T(co_usuari, li_botpar, co_pagina, co_vuelta, co_pagbot, id_frawor, co_conten, co_conori, il_proces, ti_conten, co_conpad, false, il_authen, no_confir, no_target);
            $D.cancel();
        };
        $D.wakeup();
        $D.confirm(accion.no_confir);
        $D.g_ID("confirmacion_boton_no").focus();
        $D.g_ID("confirmacion_boton_si").focus();
        return;
    } else if (accion.il_authen) {
        $D.g_ID("block_pane4_message_error").innerHTML = "";
        $D.g_ID("block_pane4_password").value = "";
        $D.g_ID('block_pane4_password').setAttribute('onKeydown', "if(event.keyCode==13){$D.g_ID('block_pane4_boton_aceptar').onclick();return false;}");
        $D.g_ID("block_pane4_boton_cancelar").onclick = function () {
            $D.wakeup();
            $D.cancel();
            $D.deauthen();
        };
        $D.g_ID("block_pane4_boton_aceptar").onclick = function () {
            var pass = $D.g_ID("block_pane4_password").value;
            pass = hex_md5(pass);
            var proces = $D.getTEXT("wfp?xact=10&p_pw_usuari=" + pass + "&p_co_usulog=" + accion.co_usuari);
            proces = proces.trim();
            if (proces == 't' | proces == 'true') {
                $D.deauthen();
                iqaro_T(co_usuari, li_botpar, co_pagina, co_vuelta, co_pagbot, id_frawor, co_conten, co_conori, il_proces, ti_conten, co_conpad, false, false, no_confir, no_target);
            } else {
                $D.g_ID("block_pane4_message_error").innerHTML = "Password incorrecto";
                $D.g_ID("block_pane4_password").focus();
            }
        };
        $D.wakeup();
        $D.cancel();
        $D.authen();
        $D.g_ID("block_pane4_password").focus();
        return;
    }

    var b_tr = $D.g_ID("button_" + accion.co_pagina + "_" + accion.co_vuelta + "_" + accion.co_pagbot);
    try {
        b_tr = b_tr.getParent();
    } catch (e) {
        b_tr = b_tr.parentNode;
    }
    try {
        b_tr = b_tr.getParent();
    } catch (e) {
        b_tr = b_tr.parentNode;
    }
//console.log("m_tr:"+b_tr.innerHTML);

    accion.addInput($D.n_E('input', 'co_pagina', 'hidden', accion.co_pagina));
    accion.addInput($D.n_E('input', 'co_conten', 'hidden', accion.co_condes));
    accion.addInput($D.n_E('input', 'co_conori', 'hidden', accion.co_conten));
    accion.addInput($D.n_E('input', 'item', 'hidden', $D.g_ID("item").value));
    if (co_conpad != null | co_conpad != undefined | co_conpad != '')
        accion.addInput($D.n_E('input', 'co_conpad', 'hidden', co_conpad));
    accion.addInput($D.n_E('input', 'co_pagbot', 'hidden', accion.co_pagbot));
    accion.addInput($D.n_E('input', 'id_fraant', 'hidden', accion.id_frawor));
    accion.addInput($D.n_E('input', 'cabecera', 'hidden', "false"));
    accion = iqaro_tabla_loadinputs2(accion, getElementsByClassName(b_tr, "q"));
    var l = accion.getLi_inputs();
    accion.setIs_compus(accion.getLi_compus().length > 0 ? true : false);
    sub_accion2(accion);
}

function sub_accion2(accion) {
    if (accion.getIs_compus()) {
        var $O = null;
        for (var i = 0; i < accion.getLi_compus().length; i++) {
            if (!accion.getLi_compus()[i].is_process) {
                $O = accion.getLi_compus()[i];
                i = accion.getLi_compus().length - 1;
            }
        }

        if ($O != null) {
            var p = $D.g_ID($O.id_valore);
            var x = null;
            try {
                x = p.contentWindow.document.getElementById('va_regist_file').getAttribute('nuevo');
            } catch (e) {
                x = false;
            }

            if (x == 'true') {
                if (p.contentWindow.document.getElementById("va_regist_file").value == "") {
                    $O.no_valore = '';
                    if ($O.getCo_conpar())
                        $O.getCo_conpar().setAttribute("value", $O.no_valore);
                    if ($O.getVa_pagreg())
                        $O.getVa_pagreg().setAttribute("value", $O.no_valore);
                    if ($O.getCo_conpar())
                        accion.addInput($O.getCo_conpar());
                    if ($O.getVa_pagreg())
                        accion.addInput($O.getVa_pagreg());
                    $O.is_process = true;
                    setTimeout(function () {
                        sub_accion2(accion);
                    }, 1000);
                } else {
                    if ($O.is_submit) {
                        var R = p.contentWindow.document.getElementById("NAME_FILE").getAttribute("name");
                        if (R == undefined | R == "")
                            setTimeout(function () {
                                sub_accion2(accion);
                            }, 1000);
                        else {
                            //si encontro data
                            $O.no_valore = R;
                            if ($O.getCo_conpar())
                                $O.getCo_conpar().setAttribute("value", $O.no_valore);
                            if ($O.getVa_pagreg())
                                $O.getVa_pagreg().setAttribute("value", $O.no_valore);
                            if ($O.getCo_conpar())
                                accion.addInput($O.getCo_conpar());
                            if ($O.getVa_pagreg())
                                accion.addInput($O.getVa_pagreg());
                            $O.is_process = true;
                            //accion.getLi_compus()[el_i] = $O;
                            setTimeout(function () {
                                sub_accion2(accion);
                            }, 10000);
                        }
                    } else {
                        $D.wait_msg(p.contentWindow.document.getElementById("va_regist_file").value);
                        p.contentWindow.document.getElementById("form_data").submit();
                        $O.is_submit = true;
                        setTimeout(function () {
                            sub_accion2(accion);
                        }, 1000);
                        return;
                    }
                }
            } else {
                var R = null;
                try {
                    R = p.contentWindow.document.getElementById("NAME_FILE").getAttribute("name");
                } catch (e) {
                    R = "";
                }

                if (R == undefined | R == "" | R == null)
                    setTimeout(function () {
                        sub_accion2(accion);
                    }, 1000);
                else {
                    $O.no_valore = R;
                    if ($O.getCo_conpar())
                        $O.getCo_conpar().setAttribute("value", $O.no_valore);
                    if ($O.getVa_pagreg())
                        $O.getVa_pagreg().setAttribute("value", $O.no_valore);
                    if ($O.getCo_conpar())
                        accion.addInput($O.getCo_conpar());
                    if ($O.getVa_pagreg())
                        accion.addInput($O.getVa_pagreg());
                    $O.is_process = true;
                    //accion.getLi_compus()[el_i] = $O;
                    setTimeout(function () {
                        sub_accion2(accion);
                    }, 1000);
                }
            }
        } else {
            accion.setIs_compus(false);
            setTimeout(function () {
                sub_accion2(accion);
            }, 1000);
        }
    } else {
        $D.wait_msg("Operaci&oacute;n en proceso...");
        if (accion.getIs_propag()) {
            if (accion.getIs_submit()) {
                var proces = $D.g_ID("pagreg").contentWindow.document.getElementsByTagName("BODY")[0];
                if (($D.g_ID("pagreg").contentWindow.document.getElementById("form_data") == undefined | $D.g_ID("pagreg").contentWindow.document.getElementById("form_data") == null) & (proces != undefined | proces != null)) {
                    if (proces.innerHTML.length > 0) {
                        if (proces.innerHTML == "OK" & (accion.ti_conten == "wf" | accion.ti_conten == "wf2")) {
                            var f;
                            if (accion.ti_conten == "wf" | accion.ti_conten == "wf2") {
                                f = $D.g_ID("m_f");
                                f.name = "m_f";
                            } else {
                                f = $D.g_ID("m_fl");
                                f.name = "m_fl";
                            }
                            f.action = $D.base() + "/" + accion.ti_conten;
                            f.method = 'POST';
                            f.innerHTML = "";
                            accion.addInput($D.n_E('input', 'fe_solini', 'hidden', new Date().getTime()));
                            //                            alert("aqui->");
                            for (var i = 0; i < accion.getLi_inputs().length; i++) {
                                f.appendChild(accion.getLi_inputs()[i]);
                            }
                            if (accion.no_target == null)
                                f.removeAttribute("target")
                            else {
                                f.setAttribute("target", accion.no_target);
                                $D.wakeup();
                            }
                            f.submit();
                        } else if (proces.innerHTML == "OK" & accion.ti_conten == "wfl") {
                            try {
                                var proces2 = $D.getJSONE($D.base() + "/wfp?xact=13&id_frawor=" + accion.id_frawor + "&co_conten=" + accion.co_conten);
                                if (proces2 == undefined) {
                                    proces2 = $D.getJSON($D.base() + "/wfp?xact=13&id_frawor=" + accion.id_frawor + "&co_conten=" + accion.co_conten);
                                }
                                window.returnValue = proces2;
                                window.close();
                            } catch (ep) {
                            }
                        } else {
                            $D.g_ID("block_pane2").style.display = "none";
                            mensaje(null, proces.innerHTML, null, null, 1)
                        }
                    } else {
                        setTimeout(function () {
                            sub_accion2(accion);
                        }, 1000);
                    }
                } else {
                    setTimeout(function () {
                        sub_accion2(accion);
                    }, 1000);
                }
            } else {
                var wfp_fr = $D.g_ID("pagreg");
                var f_wfp = wfp_fr.contentWindow.document.getElementById("form_data");
                f_wfp.action = $D.base() + "/wfp?xact=5&propag=1&borrar=1&id_frawor=" + accion.id_frawor;
                f_wfp.method = 'POST';
                f_wfp.innerHTML = "";
                for (var i = 0; i < accion.getLi_inputs().length; i++) {
                    if (!(accion.getLi_inputs()[i].getAttribute("name").indexOf("va_vapreg") == 0))
                        f_wfp.appendChild(accion.getLi_inputs()[i]);
                }
//                alert("antes de submear");
                f_wfp.submit();
                accion.setIs_submit(true);
                setTimeout(function () {
                    sub_accion2(accion);
                }, 1000);
            }
        } else {
//            alert("No es propag");
            var f;
            if (accion.ti_conten == "wf" | accion.ti_conten == "wf2") {
                f = $D.g_ID("m_f");
                f.name = "m_f";
            } else {
                f = $D.g_ID("m_fl");
                f.name = "m_fl";
            }
            f.action = $D.base() + "/" + accion.ti_conten;
            f.method = 'POST';
            f.innerHTML = "";
            accion.addInput($D.n_E('input', 'fe_solini', 'hidden', new Date().getTime()));
            for (var i = 0; i < accion.getLi_inputs().length; i++) {
                f.appendChild(accion.getLi_inputs()[i]);
            }
            if (accion.no_target == null)
                f.removeAttribute("target")
            else {
                f.setAttribute("target", accion.no_target);
                $D.wakeup(false);
            }
            f.submit();
        }
    }
}


function iqaro_T_A(co_usuari, li_botpar, co_pagina, co_pagbot, id_frawor, co_conten, co_conori, il_proces, ti_conten, co_conpad, il_confirm, il_authen, no_confir, no_parurl, no_target) {
    $D.wait();
    var accion = new Action({
        co_usuari: co_usuari,
        li_botpar: li_botpar,
        co_pagina: co_pagina,
        no_parurl: no_parurl,
        co_pagbot: co_pagbot,
        id_frawor: id_frawor,
        co_condes: co_conten,
        co_conten: co_conori,
        ti_conten: ti_conten,
        no_target: no_target,
        is_propag: il_proces,
        il_confirm: il_confirm,
        il_authen: il_authen,
        no_confir: no_confir
    });
    var tb = $D.g_ID("tb" + accion.co_pagina);
    if (accion.il_confirm) {
        $D.g_ID("confirmacion_boton_si").onclick = function () {
            iqaro_T_A(co_usuari, li_botpar, co_pagina, co_pagbot, id_frawor, co_conten, co_conori, il_proces, ti_conten, co_conpad, false, il_authen, no_confir, no_parurl, no_target);
            $D.cancel();
        };
        $D.wakeup();
        $D.confirm(accion.no_confir);
        $D.g_ID("confirmacion_boton_no").focus();
        $D.g_ID("confirmacion_boton_si").focus();
        return;
    } else if (accion.il_authen) {
        $D.g_ID("block_pane4_message_error").innerHTML = "";
        $D.g_ID("block_pane4_password").value = "";
        $D.g_ID('block_pane4_password').setAttribute('onKeydown', "if(event.keyCode==13){$D.g_ID('block_pane4_boton_aceptar').onclick();return false;}");
        $D.g_ID("block_pane4_boton_cancelar").onclick = function () {
            $D.wakeup();
            $D.cancel();
            $D.deauthen();
        };
        $D.g_ID("block_pane4_boton_aceptar").onclick = function () {
            var pass = $D.g_ID("block_pane4_password").value;
            pass = hex_md5(pass);
            var proces = $D.getTEXT($D.base() + "/wfp?xact=10&p_pw_usuari=" + pass + "&p_co_usulog=" + accion.co_usuari);
            proces = proces.trim();
            if (proces == 't' | proces == 'true') {
                $D.deauthen();
                iqaro_T_A(co_usuari, li_botpar, co_pagina, co_pagbot, id_frawor, co_conten, co_conori, il_proces, ti_conten, co_conpad, false, false, no_confir, no_parurl, no_target);
            } else {
                $D.g_ID("block_pane4_message_error").innerHTML = "Password incorrecto";
                $D.g_ID("block_pane4_password").focus();
            }
        };
        $D.wakeup();
        $D.cancel();
        $D.authen();
        $D.g_ID("block_pane4_password").focus();
        return;
    }

    accion.addInput($D.n_E('input', 'co_pagina', 'hidden', accion.co_pagina));
    accion.addInput($D.n_E('input', 'co_conten', 'hidden', accion.co_condes));
    accion.addInput($D.n_E('input', 'co_conori', 'hidden', accion.co_conten));
    accion.addInput($D.n_E('input', 'item', 'hidden', $D.g_ID("item").value));
    if (co_conpad != null | co_conpad != undefined | co_conpad != '')
        accion.addInput($D.n_E('input', 'co_conpad', 'hidden', co_conpad));
    accion.addInput($D.n_E('input', 'co_pagbot', 'hidden', accion.co_pagbot));
    accion.addInput($D.n_E('input', 'id_fraant', 'hidden', accion.id_frawor));
    accion.addInput($D.n_E('input', 'cabecera', 'hidden', "false"));
    accion = iqaro_tabla_loadinputs3(accion, tb);
    var l = accion.getLi_inputs();
    for (var i = 0; i < l.length; i++) {
        console.log("-->" + l[i] + "::" + l[i].tagName + "::" + l[i].name + "::" + l[i].value);
    }

    l = accion.getLi_compus();
    for (var i = 0; i < l.length; i++) {
        console.log("-->" + l[i] + "::" + l[i].id_valore + "::" + l[i].co_vuelta);
    }

    accion.setIs_compus(accion.getLi_compus().length > 0 ? true : false);
    sub_accion3(accion);
}

function iqaro_tabla_loadinputs3(accion, T) {
    var filas = T.rows;
    for (var i = 0; i < filas.length; i++) {
        var $si = getElementsByClassName(filas[i], "q s");
        if ($si.length == 0) {
            var es = filas[i].getElementsByTagName("*");
            for (var o = 0; o < es.length; o++) {
                if (es[o].className.indexOf('q s') > -1)
                    $si[$si.length] = es[o];
            }
        }
        for (var n_ = 0; n_ < $si.length; n_++) {
            var $c = $si[n_];
            var z;
            var ts = $c.id.replace("v" + accion.co_pagina + "_", "");
            var reg_par = accion.li_botpar.split(",");
            if ($c.id.split("_").length == 3) {
                $c.id = $c.id.split("_")[2];
            }

            if ($c.tagName == "INPUT") {
                accion.addInput($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + (i + 1) + "_" + $c.id, 'hidden', $c.value));
            } else if ($c.tagName == "LABEL") {
                accion.addInput($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + (i + 1) + "_" + $c.id, 'hidden', ($c.getAttribute("v") == undefined) ? $c.innerHTML : $c.getAttribute("v")));
            } else if ($c.tagName == "SELECT") {
                if ($c.options.length == 0) {
                    accion.addInput($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + (i + 1) + "_" + $c.id, 'hidden', ''));
                } else {
                    accion.addInput($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + (i + 1) + "_" + $c.id, 'hidden', $c.options[$c.selectedIndex].value));
                }
            } else if ($c.tagName == "TEXTAREA") {
                accion.addInput($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + (i + 1) + "_" + $c.id, 'hidden', $c.value.replace(/\r\n/g, "&0A")));
            } else if ($c.tagName == "IFRAME") {
                var p = $D.g_ID($c.id);
                var ps = p.contentWindow.document.getElementById("NAME_FILE");
                if (ps == null | ps == undefined) {
                    try {
                        accion.addInput($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + (i + 1) + "_" + $c.id, 'hidden', p.contentWindow.editor.getValue()));
                    }
                    catch (e) {
                    }
                } else if (ps.getAttribute("estado") == "UNCOMPLETE") {
                    var oc = new Oc({
                        id_valore: $c.id,
                        co_vuelta: (i + 1)
                    });
                    oc.setVa_pagreg($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + (i + 1) + "_" + $c.id, 'hidden', ''));
                    accion.addCompus(oc);
                } else {
                    accion.addInput($D.n_E('input', "va_regist_" + accion.co_pagina + "_" + (i + 1) + "_" + $c.id, 'hidden', ps.getAttribute("name")));
                }
            }
        }
    }

    return accion;
}

function sub_accion3(accion) {
    if (accion.getIs_compus()) {
        var $O = null;
        for (var i = 0; i < accion.getLi_compus().length; i++) {
            if (!accion.getLi_compus()[i].is_process) {
                $O = accion.getLi_compus()[i];
                i = accion.getLi_compus().length - 1;
            }
        }

        if ($O != null) {
            var p = null;
            var l_i = $D.g_ID("tb" + accion.co_pagina).rows[$O.co_vuelta - 1].getElementsByTagName("IFRAME");
            for (var r = 0; r < l_i.length; r++) {
                if (l_i[r].id == $O.id_valore) {
                    p = l_i[r];
                    r = l_i.length - 1;
                }
            }

            var x = null;
            try {
                x = p.contentWindow.document.getElementById('va_regist_file').getAttribute('nuevo');
            } catch (e) {
                x = false;
            }

            if (x == 'true') {
                if (p.contentWindow.document.getElementById("va_regist_file").value == "") {
                    $O.no_valore = '';
                    if ($O.getCo_conpar())
                        $O.getCo_conpar().setAttribute("value", $O.no_valore);
                    if ($O.getVa_pagreg())
                        $O.getVa_pagreg().setAttribute("value", $O.no_valore);
                    if ($O.getCo_conpar())
                        accion.addInput($O.getCo_conpar());
                    if ($O.getVa_pagreg())
                        accion.addInput($O.getVa_pagreg());
                    $O.is_process = true;
                    setTimeout(function () {
                        sub_accion3(accion);
                    }, 1000);
                } else {
                    if ($O.is_submit) {
                        var R = p.contentWindow.document.getElementById("NAME_FILE").getAttribute("name");
                        if (R == undefined | R == "")
                            setTimeout(function () {
                                sub_accion3(accion);
                            }, 1000);
                        else {
                            //si encontro data
                            $O.no_valore = R;
                            if ($O.getCo_conpar())
                                $O.getCo_conpar().setAttribute("value", $O.no_valore);
                            if ($O.getVa_pagreg())
                                $O.getVa_pagreg().setAttribute("value", $O.no_valore);
                            if ($O.getCo_conpar())
                                accion.addInput($O.getCo_conpar());
                            if ($O.getVa_pagreg())
                                accion.addInput($O.getVa_pagreg());
                            $O.is_process = true;
                            setTimeout(function () {
                                sub_accion3(accion);
                            }, 10000);
                        }
                    } else {
                        $D.wait_msg(p.contentWindow.document.getElementById("va_regist_file").value);
                        p.contentWindow.document.getElementById("form_data").submit();
                        $O.is_submit = true;
                        setTimeout(function () {
                            sub_accion3(accion);
                        }, 1000);
                        return;
                    }
                }
            } else {
                var R = null;
                try {
                    R = p.contentWindow.document.getElementById("NAME_FILE").getAttribute("name");
                } catch (e) {
                    R = "";
                }

                if (R == undefined | R == "" | R == null)
                    setTimeout(function () {
                        sub_accion3(accion);
                    }, 1000);
                else {
                    $O.no_valore = R;
                    if ($O.getCo_conpar())
                        $O.getCo_conpar().setAttribute("value", $O.no_valore);
                    if ($O.getVa_pagreg())
                        $O.getVa_pagreg().setAttribute("value", $O.no_valore);
                    if ($O.getCo_conpar())
                        accion.addInput($O.getCo_conpar());
                    if ($O.getVa_pagreg())
                        accion.addInput($O.getVa_pagreg());
                    $O.is_process = true;
                    setTimeout(function () {
                        sub_accion3(accion);
                    }, 1000);
                }
            }
        } else {
            accion.setIs_compus(false);
            setTimeout(function () {
                sub_accion3(accion);
            }, 1000);
        }
    } else {
        $D.wait_msg("Operaci&oacute;n en proceso...");
        if (accion.getIs_propag()) {
            if (accion.getIs_submit()) {
                var proces = $D.g_ID("pagreg").contentWindow.document.getElementsByTagName("BODY")[0];
                if (($D.g_ID("pagreg").contentWindow.document.getElementById("form_data") == undefined | $D.g_ID("pagreg").contentWindow.document.getElementById("form_data") == null) & (proces != undefined | proces != null)) {
                    if (proces.innerHTML.length > 0) {
                        if (proces.innerHTML == "OK" & (accion.ti_conten == "wf" | accion.ti_conten == "wf2")) {
                            var f;
                            if (accion.ti_conten == "wf" | accion.ti_conten == "wf2") {
                                f = $D.g_ID("m_f");
                                f.name = "m_f";
                            } else {
                                f = $D.g_ID("m_fl");
                                f.name = "m_fl";
                            }
                            if (accion.co_condes == accion.co_conten) {
                                f.action = $D.base() + "/" + accion.ti_conten + "?" + accion.no_parurl;
                            } else {
                                f.action = $D.base() + "/" + accion.ti_conten;
                            }
                            f.method = 'POST';
                            f.innerHTML = "";
                            accion.addInput($D.n_E('input', 'fe_solini', 'hidden', new Date().getTime()));
                            for (var i = 0; i < accion.getLi_inputs().length; i++) {
                                f.appendChild(accion.getLi_inputs()[i]);
                            }
                            if (accion.no_target == null)
                                f.removeAttribute("target")
                            else {
                                f.setAttribute("target", accion.no_target);
                                $D.wakeup();
                            }
                            f.submit();
                        } else if (proces.innerHTML == "OK" & accion.ti_conten == "wfl") {
                            try {
                                var proces2 = $D.getJSONE($D.base() + "/wfp?xact=13&id_frawor=" + accion.id_frawor + "&co_conten=" + accion.co_conten);
                                if (proces2 == undefined) {
                                    proces2 = $D.getJSON($D.base() + "/wfp?xact=13&id_frawor=" + accion.id_frawor + "&co_conten=" + accion.co_conten);
                                }
                                window.returnValue = proces2;
                                window.close();
                            } catch (ep) {
                            }
                        } else {
                            $D.g_ID("block_pane2").style.display = "none";
                            mensaje(null, proces.innerHTML, null, null, 1)
                        }
                    } else {
                        setTimeout(function () {
                            sub_accion3(accion);
                        }, 1000);
                    }
                } else {
                    setTimeout(function () {
                        sub_accion3(accion);
                    }, 1000);
                }
            } else {
                var wfp_fr = $D.g_ID("pagreg");
                var f_wfp = wfp_fr.contentWindow.document.getElementById("form_data");
                f_wfp.action = $D.base() + "/wfp?xact=5&propag=1&borrar=1&id_frawor=" + accion.id_frawor;
                f_wfp.method = 'POST';
                f_wfp.innerHTML = "";
                for (var i = 0; i < accion.getLi_inputs().length; i++) {
                    if (!(accion.getLi_inputs()[i].getAttribute("name").indexOf("va_vapreg") == 0))
                        f_wfp.appendChild(accion.getLi_inputs()[i]);
                }
                f_wfp.submit();
                accion.setIs_submit(true);
                setTimeout(function () {
                    sub_accion3(accion);
                }, 1000);
            }
        } else {
            var f;
            if (accion.ti_conten == "wf" | accion.ti_conten == "wf2") {
                f = $D.g_ID("m_f");
                f.name = "m_f";
            } else {
                f = $D.g_ID("m_fl");
                f.name = "m_fl";
            }
            if (accion.co_condes == accion.co_conten) {
                f.action = $D.base() + "/" + accion.ti_conten + "?" + accion.no_parurl;
            } else {
                f.action = $D.base() + "/" + accion.ti_conten;
            }
            f.method = 'POST';
            f.innerHTML = "";
            accion.addInput($D.n_E('input', 'fe_solini', 'hidden', new Date().getTime()));
            for (var i = 0; i < accion.getLi_inputs().length; i++) {
                f.appendChild(accion.getLi_inputs()[i]);
            }
            if (accion.no_target == null)
                f.removeAttribute("target")
            else {
                f.setAttribute("target", accion.no_target);
                $D.wakeup();
            }
            f.submit();
        }
    }
}

function iqaro_tabla_all_tr_proces_confirm(sCoUsuari, no_confirm, regpar, id_pag, v, boton, id_frawor, co_conten, co_conori, p_co_pagbot, wf, target) {
    $D.g_ID("modalDialogPageBackground").style.display = "block";
    $D.g_ID("confirmacion_message").innerHTML = "" + no_confirm;
    $D.g_ID("confirmacion_boton_si").setAttribute("onclick", "$D.g_ID('confirmacion').style.display='none';$D.g_ID('modalDialogPageBackground').style.display='none';iqaro_tabla_all_tr_proces('" + regpar + "','" + id_pag + "','" + v + "','" + boton + "','" + id_frawor + "','" + co_conten + "', '" + co_conori + "','" + p_co_pagbot + "','" + wf + "','" + target + "');return false;");
    $D.g_ID("confirmacion").style.display = "block";
    $D.g_ID("confirmacion_boton_no").focus();
}

function iqaro_tabla_all_tr_proces_confirm_password(sCoUsuari, no_confirm, regpar, id_pag, v, boton, id_frawor, co_conten, co_conori, p_co_pagbot, wf, target) {
    $D.g_ID("modalDialogPageBackground").style.display = "block";
    $D.g_ID("confirmacion_message").innerHTML = "" + no_confirm;
    $D.g_ID("confirmacion_boton_si").setAttribute("onclick", "$D.g_ID('confirmacion').style.display='none';$D.g_ID('modalDialogPageBackground').style.display='none';iqaro_tabla_all_tr_proces_password('" + sCoUsuari + "','" + no_confirm + "','" + regpar + "','" + id_pag + "','" + v + "','" + boton + "','" + id_frawor + "','" + co_conten + "', '" + co_conori + "','" + p_co_pagbot + "','" + wf + "','" + target + "');return false;");
    $D.g_ID("confirmacion").style.display = "block";
    $D.g_ID("confirmacion_boton_no").focus();
}

function iqaro_tabla_all_tr_proces_password(sCoUsuari, no_confirm, regpar, id_pag, v, boton, id_frawor, co_conten, co_conori, p_co_pagbot, wf, target) {
    $D.g_ID('block_pane4_password').setAttribute('onKeydown', "if(event.keyCode==13){$D.g_ID('block_pane4_boton_aceptar').onclick();return false;}");
    $D.g_ID("confirmacion").style.display = "none";
    $D.g_ID("modalDialogPageBackground").style.display = "block";
    $D.g_ID("block_pane4_boton_aceptar").setAttribute("onclick", "validar_usuario_all_tr('" + sCoUsuari + "','" + no_confirm + "','" + regpar + "','" + id_pag + "','" + v + "','" + boton + "','" + id_frawor + "','" + co_conten + "', '" + co_conori + "','" + p_co_pagbot + "','" + wf + "','" + target + "');return false;");
    $D.g_ID("block_pane4").style.display = "block";
    $D.g_ID("block_pane4_password").focus();
}

function validar_usuario_all_tr(sCoUsuari, no_confirm, regpar, id_pag, v, boton, id_frawor, co_conten, co_conori, p_co_pagbot, wf, target) {
    var autent = false;
    var pass = $D.g_ID("block_pane4_password").value;
    pass = hex_md5(pass);
    var proces = $D.getTEXT($D.base() + "/wfp?xact=10&p_pw_usuari=" + pass + "&p_co_usulog=" + sCoUsuari);
    proces = proces.trim();
    if (proces == 't' | proces == 'true') {
        $D.g_ID("block_pane4").style.display = "none";
        iqaro_tabla_all_tr_proces(regpar, id_pag, v, boton, id_frawor, co_conten, co_conori, p_co_pagbot, wf, target);
    } else {
        $D.g_ID("block_pane4_message_error").innerHTML = "Password incorrecto";
        $D.g_ID("block_pane4_password").focus();
    }
}

function iqaro_tabla_all_tr(regpar, id_pag, v, boton, id_frawor, co_conten, co_conori, p_co_pagbot, wf, target) {
    var reg_par = regpar;
    var m_tr = $D.g_ID("tb" + id_pag);
    var f = $D.g_ID("m_f");
    f.action = $D.base() + "/" + wf;
    f.method = 'POST';
    f.innerHTML = "";
    if (co_conori == co_conten) {
        var parametros = reg_par.split("&");
        for (var t = 0; t < parametros.length; t++) {
            var pa = parametros[t];
            if (pa.length > 0) {
                if (pa.split("=")[0].substring(0, 10) == "co_conpar_") {
                    var re_g = $D.n_E('input', pa.split("=")[0], 'hidden', pa.split("=")[1]);
                    f.appendChild(re_g);
                }
            }
        }
    }

    var ti_bot = $D.n_E('input', "ti_pagbot", 'hidden', 'G');
    f.appendChild(ti_bot);
    var co_p = $D.n_E('input', "co_pagina", 'hidden', id_pag);
    f.appendChild(co_p);
    var co_c = $D.n_E('input', "co_conten", 'hidden', co_conten);
    f.appendChild(co_c);
    var co_co = $D.n_E('input', "co_conori", 'hidden', co_conori);
    f.appendChild(co_co);
    var co_pb = $D.n_E('input', 'co_pagbot', 'hidden', p_co_pagbot);
    f.appendChild(co_pb);
    var id_tf = $D.n_E('input', 'id_fraant', 'hidden', id_frawor);
    f.appendChild(id_tf);
    var id_fe = $D.n_E('input', 'fe_solini', 'hidden', new Date().getTime());
    f.appendChild(id_fe);
    var cabecera = $D.n_E('input', 'cabecera', 'hidden', "false");
    f.appendChild(cabecera);
    for (var i = 0; i < m_tr.rows.length; i++) {
        var n_tr = m_tr.rows[i];
        var items = getElementsByClassName(n_tr, "s");
        for (var n_ = 0; n_ < items.length; n_++) {
            var componente = items[n_];
            var n_i = $D.n_E('input');
            n_i.type = 'hidden';
            n_i.name = "va_regist_" + id_pag + "_" + (i + 1) + "_" + componente.id;
            if (componente.tagName == "INPUT") {
                n_i.value = componente.value;
                f.appendChild(n_i);
            } else if (componente.tagName == "LABEL") {
                n_i.value = componente.innerHTML;
                f.appendChild(n_i);
            } else if (componente.tagName == "SELECT") {
                n_i.value = componente.value;
                if (componente.options.length == 0) {
                    n_i.value = "";
                } else {
                    n_i.value = componente.value;
                }
                f.appendChild(n_i);
            } else if (componente.tagName == "TEXTAREA") {
                n_i.value = componente.value;
                f.appendChild(n_i);
            }
        }
    }

    $D.g_ID("modalDialogPageBackground").style.display = "block";
    $D.g_ID("block_pane2").style.display = "block";
    f.submit();
}

function iqaro_tabla_all_tr_proces(regpar, id_pag, v, boton, id_frawor, co_conten, co_conori, p_co_pagbot, wf, target) {
    var reg_par = regpar;
    var m_tr = $D.g_ID("tb" + id_pag);
    var f = $D.g_ID("m_f");
    f.action = $D.base() + "/" + wf;
    f.method = 'POST';
    f.innerHTML = "";
    if (co_conori == co_conten) {
        var parametros = reg_par.split("&");
        for (var t = 0; t < parametros.length; t++) {
            var pa = parametros[t];
            if (pa.length > 0) {
                if (pa.split("=")[0].substring(0, 10) == "co_conpar_") {
                    var re_g = $D.n_E('input', pa.split("=")[0], 'hidden', pa.split("=")[1]);
                    f.appendChild(re_g);
                }
            }
        }
    }

    wfp_fr = $D.g_ID("pagreg");
    var f_wfp = wfp_fr.contentWindow.document.getElementById("form_data");
    if (f_wfp != null && f_wfp != undefined) {
        wfp_fr.contentWindow.document.body.removeChild(f_wfp);
    }
    f_wfp = wfp_fr.contentWindow.document.createElement("form");
    wfp_fr.contentWindow.document.body.appendChild(f_wfp);
    f_wfp.id = "form_data";
    f_wfp.setAttribute("method", "post");
    f_wfp = wfp_fr.contentWindow.document.getElementById("form_data");
    f_wfp.action = $D.base() + "/wfp?xact=5&propag=1&borrar=1&id_frawor=" + id_frawor;
    var co_p = $D.n_E('input', "co_pagina", 'hidden', id_pag);
    f_wfp.appendChild(co_p);
    var id_tf = $D.n_E('input', 'id_fraant', 'hidden', id_frawor);
    f.appendChild(id_tf);
    var cabecera = $D.n_E('input', 'cabecera', 'hidden', "false");
    f.appendChild(cabecera);
    var co_c = $D.n_E('input', "co_conten", 'hidden', co_conten);
    f.appendChild(co_c);
    co_c = $D.n_E('input', "co_conten", 'hidden', co_conten);
    f_wfp.appendChild(co_c);
    var co_co = $D.n_E('input', "co_conori", 'hidden', co_conori);
    f.appendChild(co_co);
    co_co = $D.n_E('input', "co_conori", 'hidden', co_conori);
    f_wfp.appendChild(co_co);
    var co_pb = $D.n_E('input', 'co_pagbot', 'hidden', p_co_pagbot);
    f.appendChild(co_pb);
    co_pb = $D.n_E('input', 'co_pagbot', 'hidden', p_co_pagbot);
    f_wfp.appendChild(co_pb);
    for (var i = 0; i < m_tr.rows.length; i++) {
        var n_tr = m_tr.rows[i];
        var items = getElementsByClassName(n_tr, "s");
        for (var n_ = 0; n_ < items.length; n_++) {
            var componente = items[n_];
            var n_i = $D.n_E('input');
            var va_reg;
            n_i.type = 'hidden';
            n_i.name = "va_regist_" + id_pag + "_" + (i + 1) + "_" + componente.id;
            if (componente.tagName == "INPUT") {
                if (componente.className == "input2 q s" | componente.className == "input2t q s") {
                    n_i.name = "va_regist_" + id_pag + "_" + (i + 1) + "_" + componente.id.split("_")[2];
                }
                n_i.value = componente.value;
                va_reg = $D.n_E('input', n_i.name, 'hidden', componente.value);
                f_wfp.appendChild(va_reg);
            } else if (componente.tagName == "LABEL") {
                var pp = "" + componente.getAttribute("v");
                if (pp != 'null') {
                    n_i.value = componente.getAttribute("v");
                    va_reg = $D.n_E('input', n_i.name, 'hidden', componente.getAttribute("v"));
                    f_wfp.appendChild(va_reg);
                } else {
                    n_i.value = componente.innerHTML;
                    va_reg = $D.n_E('input', n_i.name, 'hidden', componente.innerHTML);
                    f_wfp.appendChild(va_reg);
                }
            } else if (componente.tagName == "SELECT") {
                n_i.value = componente.value;
                if (componente.options.length == 0) {
                    n_i.value = "";
                    va_reg = $D.n_E('input', n_i.name, 'hidden', '');
                    f_wfp.appendChild(va_reg);
                } else {
                    n_i.value = componente.value;
                    va_reg = $D.n_E('input', n_i.name, 'hidden', componente.value);
                    f_wfp.appendChild(va_reg);
                }
            } else if (componente.tagName == "TEXTAREA") {
                n_i.value = componente.value;
                va_reg = $D.n_E('input', n_i.name, 'hidden', componente.value);
                f_wfp.appendChild(va_reg);
            }
        }
    }

    $D.g_ID("modalDialogPageBackground").style.display = "block";
    $D.g_ID("block_pane2").style.display = "block";
    wfp_fr.addEventListener('load', function () {
        var frame = $D.g_ID("pagreg");
        var proces = frame.contentWindow.document.getElementsByTagName("BODY")[0].innerHTML;
        if (frame.contentWindow.document.getElementById("form_data") == null) {
            if (proces == 'OK') {
                f.submit();
            } else {
                $D.g_ID("block_pane2").style.display = "none";
                mensaje(null, proces, null, null, 1)
            }
        }

    }, false);
    f_wfp.submit();
}




function actualizaradio(r, e) {
    $D.g_ID(e).value = r.value;
    if ($D.g_ID(e).getAttribute("onchange") != null) {
        $D.g_ID(e).onchange();
    } else {
        $D.g_ID(e).setAttribute("onchange", "");
    }
}

function actualizacheckbox(c) {
    c.value = c.checked ? "1" : "0";
}

function nn_Key() {
    Key = event.which;
    if ((Key < 46) || (Key > 57))
        Key = 0;
}

function texto_fecha(n) {
    if (($D.g_ID('ff_anio' + n).value.toString().length == 0) & ($D.g_ID('ff_mes' + n).value.toString().length == 0) & ($D.g_ID('ff_dia' + n).value.toString().length == 0)) {
        $D.g_ID('v' + n).value = '';
    } else {
        try {
            $D.g_ID('v' + n).value = $D.g_ID('ff_anio' + n).value + '-' + $D.g_ID('ff_mes' + n).value + '-' + $D.g_ID('ff_dia' + n).value;
        } catch (e) {
            $D.g_ID('' + n).value = $D.g_ID('ff_anio' + n).value + '-' + $D.g_ID('ff_mes' + n).value + '-' + $D.g_ID('ff_dia' + n).value;
        }
    }
}

function texto_documento(n) {
    if (($D.g_ID('f_' + n).value.toString().length == 0) & ($D.g_ID('ff_' + n).value.toString().length == 0)) {
        $D.g_ID('v' + n).value = '';
    } else {
        $D.g_ID('v' + n).value = $D.g_ID('f_' + n).value + '-' + $D.g_ID('ff_' + n).value;
    }
}

function get_value_from_componente(c) {
    var v;
    switch (c.tagName) {
        case "INPUT":
            v = c.value;
            break;
        case "SELECT":
            v = c.options[c.selectedIndex].value;
            break;
        case "LABEL":
            v = c.innerHTML;
            break;
        case "TEXTAREA":
            v = c.value;
            break;
        default:
            v = "";
            break;
    }
    return v;
}

function put_value_to_componente_L(c) {
    switch (c.tagName) {
        case "INPUT":
            switch (c.type) {
                case "text":
                    var m = c.getAttribute("f");
                    if (m == null) {
                        m = "";
                    }
                    else if (m == undefined) {
                        m = "";
                    }
                    v = m;
                    break;
            }
            break;
        case "SELECT":
            var m = c.getAttribute("f");
            if (m == null) {
                m = "";
            }
            else if (m == undefined) {
                m = "";
            }
            c.setAttribute("f", m + "L");
            break;
        case "LABEL":
            var m = c.getAttribute("f");
            if (m == null) {
                m = "";
            }
            if (m == undefined) {
                m = "";
            }
            c.setAttribute("f", m + "L");
            break;
        case "TEXTAREA":
            break;
        default:
            break;
    }
}

function remove_value_to_componente_L(c) {
    switch (c.tagName) {
        case "INPUT":
            switch (c.type) {
                case "text":
                    var m = c.getAttribute("f");
                    if (m == null) {
                        m = "";
                    }
                    else if (m == undefined) {
                        m = "";
                    }
                    v = m;
                    break;
            }
            break;
        case "SELECT":
            var m = c.getAttribute("f");
            if (m == null) {
                m = "";
            }
            else if (m == undefined) {
                m = "";
            }
            if (m.length - 1 <= 0)
                c.setAttribute("f", "");
            else
                c.setAttribute("f", m.substring(0, m.length - 1));
            break;
        case "LABEL":
            var m = c.getAttribute("f");
            if (m == null) {
                m = "";
            }
            else if (m == undefined) {
                m = "";
            }
            if (m.length - 1 <= 0)
                c.setAttribute("f", "");
            else
                c.setAttribute("f", m.substring(0, m.length - 1));
            break;
        case "TEXTAREA":
            break;
        default:
            break;
    }
}

function get_value_from_componente_L(c) {
    var v;
    switch (c.tagName) {
        case "INPUT":
            switch (c.type) {
                case "text":
                    var m = c.getAttribute("f");
                    if (m == null) {
                        m = "";
                    }
                    else if (m == undefined) {
                        m = "";
                    }
                    v = m;
                    break;
                case "hidden":
                    var m = c.getAttribute("f");
                    if (m == null) {
                        m = "";
                    }
                    else if (m == undefined) {
                        m = "";
                    }
                    v = m;
                    break;
                case "radio":
                    var m = c.getAttribute("f");
                    if (m == null) {
                        m = "";
                    }
                    else if (m == undefined) {
                        m = "";
                    }
                    v = m;
                    break;
                case "checkbox":
                    var m = c.getAttribute("f");
                    if (m == null) {
                        m = "";
                    }
                    else if (m == undefined) {
                        m = "";
                    }
                    v = m;
                    break;
            }
            break;
        case "SELECT":
            var m = c.getAttribute("f");
            if (m == null) {
                m = "";
            }
            else if (m == undefined) {
                m = "";
            }
            v = m;
            break;
        case "LABEL":
            var m = c.getAttribute("f");
            if (m == null) {
                m = "";
            }
            if (m == undefined) {
                m = "";
            }
            v = m;
            break;
        case "TEXTAREA":
            v = c.getAttribute("f");
            break;
        default:
            v = "";
            break;
    }
    return v;
}

function cambio(fecha, co_regist) {
    try {
        var xx_fecha = new String(fecha.value);
        $D.g_ID('ff_dia' + co_regist).value = xx_fecha.substring(8, 10);
        $D.g_ID('ff_mes' + co_regist).value = xx_fecha.substring(5, 7);
        $D.g_ID('ff_anio' + co_regist).value = xx_fecha.substring(0, 4);
    } catch (e) {
    }
}

function isError(json) {
    var r = false;
    try {
        if (json.substr(0, 3) == '[E]')
            r = true;
    } catch (e) {
        r = false;
        e = e.toString();
    }
    return r;
}

function succes_error(id_frawor, co_pagina, co_conten) {
    var proces = null;
    if (co_pagina == '0') {
        proces = $D.getTEXT($D.base() + "/" + "wfp?xact=3&p_id_frawor=" + id_frawor + "&p_co_conten=" + co_conten);
    } else
        proces = $D.getTEXT($D.base() + "/" + "wfp?xact=3&p_id_frawor=" + id_frawor + "&p_co_pagina=" + co_pagina);
    mensaje(null, proces, null, null, 1);
}

function succes_error(id_frawor, co_pagina) {
    var proces = $D.getTEXT($D.base() + "/" + "wfp?xact=3&p_id_frawor=" + id_frawor + "&p_co_pagina=" + co_pagina);
    mensaje(null, proces, null, null, 1);
}

function succes_errorc(id_frawor, msg) {
    mensaje(null, msg, null, null, 1);
}

function mensaje(titulo, mensaje, color_titulo, color_mensaje, modo) {
    if (mensaje.length > 0) {
        $D.g_ID("modalDialogPageBackground").style.display = "block";
        if (mensaje.indexOf("{") >= 0 & mensaje.indexOf("}") > 0) {
            mensaje = mensaje.substring(mensaje.indexOf("{") + 1, mensaje.indexOf("}"));
            $D.g_ID("BP" + modo + "_error_titulo").innerHTML = (titulo == null) ? "Mensaje" : titulo;
            $D.g_ID("BP" + modo + "_MSG").style.color = (color_mensaje == null) ? "#666666" : color_mensaje;
            $D.g_ID("BP" + modo).style.borderBottom = "2px solid rgba(0, 255 ,0, 0.6)";
        } else {
            $D.g_ID("BP" + modo + "_error_titulo").innerHTML = (titulo == null) ? "Error" : titulo;
            $D.g_ID("BP" + modo + "_MSG").style.color = (color_mensaje == null) ? "red" : color_mensaje;
            $D.g_ID("BP" + modo).style.borderBottom = "2px solid rgba(255, 0, 0, 0.6)";
        }
        $D.g_ID("BP" + modo + "").style.display = "block";
        $D.g_ID("BP" + modo + "_MSG").innerHTML = mensaje;
        $D.g_ID("BP" + modo).getElementsByTagName("BUTTON")[0].focus(); //?buscar una mejor forma de obtener el foco absoluto
    }
}

function getElementsByClassName(node, classname) {
    if (node.getElementsByClassName) { // use native implementation if available
        return node.getElementsByClassName(classname);
    } else {
        return (function getElementsByClass(searchClass, node) {
            if (node == null)
                node = document;
            var classElements = [],
                    els = node.getElementsByTagName("*"),
                    elsLen = els.length,
                    pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)"), i, j;
            for (i = 0, j = 0; i < elsLen; i++) {
                if (pattern.test(els[i].className)) {
                    classElements[j] = els[i];
                    j++;
                }
            }
            return classElements;
        })(classname, node);
    }
}

function checktodo(pag, c, pr) {
    var co_pag = "t" + pag;
    var p = $D.g_ID(co_pag);
    var tds = p.getElementsByTagName("INPUT");
    for (var i = 0; i < tds.length; i++) {
        if (tds[i].type == "checkbox") {
            try {
                if (tds[i].parentNode.parentNode.parentNode.parentNode.id == co_pag) { //obtener la tablas
                    if (tds[i].id == pr) {
                        if (c.checked == true) {
                            tds[i].value = 1;
                            tds[i].checked = true;
                        } else {
                            tds[i].value = 0;
                            tds[i].checked = false;
                        }
                    }
                }
            } catch (e) {
                if (tds[i].getParent().getParent().getParent().getParent().id == co_pag) { //obtener la tablas
                    if (tds[i].id == pr) {
                        if (c.checked == true) {
                            tds[i].value = 1;
                            tds[i].checked = true;
                        } else {
                            tds[i].value = 0;
                            tds[i].checked = false;
                        }
                    }
                }
            }

        }
    }

    var tablaactual = c.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;
    var heads = document.getElementsByClassName("iqarothead")
    for (var j = 0; j < heads.length; j++) {
        if (heads[j].id == "th" + pag) {
            if (heads[j].parentNode.id != tablaactual) {
                var cb = heads[j].getElementsByTagName("INPUT");
                for (var x = 0; x < cb.length; x++) {
                    if (cb[x].type == "checkbox" && cb[x].id == c.id) {
                        cb[x].checked = c.checked;
                    }
                }
            }
        }
    }
}

var filas_offset;
function autoincrementar(co_pagina, id_frawor, co_conten, no_autinc, nu_offset) {
    var l_tr_agregar = $D.getJSON($D.base() + "/wfp?xact=14&p_co_pagina=" + co_pagina + "&p_id_frawor=" + id_frawor + "&p_co_conten=" + co_conten + "&p_nu_offset=" + nu_offset);
    var body = $D.g_ID("tb" + co_pagina);
    var trs = body.getElementsByTagName("TR");
    body.removeChild(trs[trs.length - 1]);
    trs = body.getElementsByTagName("TR");
    var boton = (trs[trs.length - 1].getElementsByTagName("BUTTON").length > 0) ? true : false;
    if (nu_offset == 1) {
        filas_offset = body.rows.length;
    }

    if (l_tr_agregar != "[E]Lista invalida") {
        for (var i = 0; i < l_tr_agregar.length; i++) {
            var tr_agregar = $D.n_E("tr");
            var l_td_agregar = l_tr_agregar[i].ts;
            var clone_tr = trs[trs.length - 1].cloneNode(true);
            var clone_tds_temp = clone_tr.childNodes;
            var clone_tds = [];
            var vuelta = parseInt(body.rows.length);
            for (var x = 0; x < clone_tds_temp.length; x++) {
                if (clone_tds_temp[x].tagName != undefined) {
                    clone_tds[clone_tds.length] = clone_tds_temp[x];
                }
            }

            for (var j = 0; j < l_td_agregar.length; j++) {
                var val_agregar = l_td_agregar[j];
                var clone_td = clone_tds[j];
                var clone_node;
                if (clone_td.tagName == "TD") {
                    for (var y = 0; y < clone_td.childNodes.length; y++) {
                        if (clone_td.childNodes[y].tagName != undefined) {
                            clone_node = clone_td.childNodes[y];
                            if (clone_node.tagName == "CENTER") {
                                for (var z = 0; z < clone_node.childNodes.length; z++) {
                                    if (clone_node.childNodes[z].tagName != undefined) {
                                        clone_node = clone_node.childNodes[z];
                                        break;
                                    }
                                }
                            }
                            break;
                        } else {
                            var texto = new XMLSerializer().serializeToString(clone_td.childNodes[y]);
                            if (parseInt(texto) != "NaN") {
                                clone_node = vuelta
                            }
                        }
                    }
                } else {
                    clone_node = clone_td;
                }

                var node_agregar;
                if (val_agregar.ti_pagreg == "1") {
                    //alert("seteando node: ti_pagreg =1");
                    if (val_agregar.ti_estreg == "L") {
                        //alert("L");
                        if (val_agregar.tx_pagreg == null)
                            node_agregar = $D.n_E("label", null, null, null, val_agregar.va_pagreg, clone_node.className, clone_node.id);
                        else {
                            node_agregar = $D.n_E("label", null, null, null, (val_agregar.tx_pagreg == null | val_agregar.tx_pagreg == "") ? val_agregar.va_pagreg : val_agregar.tx_pagreg, clone_node.className, clone_node.id);
                            node_agregar.setAttribute("v", val_agregar.va_pagreg);
                        }
                    } else if (val_agregar.ti_estreg == "E") {
                        var node_agregar2 = $D.n_E("input", null, "text", val_agregar.va_pagreg, null, "input2t q s ", clone_node.id, null, "background-color:#FFFFCC;", clone_node.getAttribute("onkeydown"));
                        node_agregar2.setAttribute("maxlength", clone_node.getAttribute("maxlength"));
                        node_agregar2.setAttribute("size", clone_node.getAttribute("size"));
                        node_agregar = $D.n_E("center");
                        node_agregar.appendChild(node_agregar2);
                    } else if (val_agregar.ti_estreg == "O") {
                        node_agregar = $D.n_E("input", null, "hidden", val_agregar.va_pagreg, null, clone_node.className, clone_node.id);
                    }
                } else if (val_agregar.ti_pagreg == "2") {
                    node_agregar = parseInt(clone_node) + 1;
                } else if (val_agregar.ti_pagreg == "3" | val_agregar.ti_pagreg == "4") {
                    node_agregar = clone_node;
                } else if (val_agregar.ti_pagreg == "6") {
                    clone_node.disabled = (val_agregar.ti_estreg == "L") ? true : false;
                    clone_node.value = val_agregar.va_pagreg;
                    if (clone_node.getAttribute("checked") != null) {
                        clone_node.removeAttribute("checked");
                    }
                    if (clone_node.getAttribute("unchecked") != null) {
                        clone_node.removeAttribute("unchecked");
                    }
                    clone_node.setAttribute((val_agregar.va_pagreg == "1") ? "checked" : "unchecked", "");
                    node_agregar = clone_node;
                }

                var td_agregar;
                if (clone_node == clone_td) {
                    td_agregar = node_agregar;
                } else {
                    td_agregar = clone_td.cloneNode(false);
                    try {
                        td_agregar.appendChild(node_agregar);
                    } catch (e) {
                        td_agregar.innerHTML = node_agregar;
                    }

                }
                //se agrega el td al tr
                tr_agregar.appendChild(td_agregar);
                if (j == l_td_agregar.length - 1) {
                    //es el ultimo
                    if (boton) {
                        clone_td = clone_tds[j + 1];
                        var td_boton_agregar = $D.n_E("TD");
                        var l_botones = clone_td.getElementsByTagName("BUTTON");
                        for (var t = 0; t < l_botones.length; t++) {
                            var btn_agregar = l_botones[t];
                            var vuelta_btn = vuelta + 1;
                            var nuevo_id = btn_agregar.id.split("_")[0] + "_" + btn_agregar.id.split("_")[1] + "_" + vuelta_btn + "_" + btn_agregar.id.split("_")[3];
                            btn_agregar.id = nuevo_id;
                            var btn_onclick_ant = btn_agregar.getAttribute("onclick").split(",");
                            var btn_onclick_new = btn_agregar.getAttribute("onclick").replace(btn_onclick_ant[2], "'" + vuelta_btn + "'").replace(btn_onclick_ant[3], "'" + nuevo_id + "'");
                            btn_agregar.setAttribute("onclick", btn_onclick_new);
                            td_boton_agregar.appendChild(btn_agregar);
                        }
                        tr_agregar.appendChild(td_boton_agregar);
                    }
                }

            }
            body.appendChild(tr_agregar);
        }
        //falta poner el boton
        console.log("c1: " + l_tr_agregar.length + " c2: " + filas_offset);
        var button = $D.n_E("BUTTON");
        button.setAttribute("onclick", "autoincrementar(" + co_pagina + "," + id_frawor + "," + co_conten + ",'" + no_autinc + "'," + (parseInt(nu_offset) + 1) + ")");
        button.innerHTML = (no_autinc == "" ? '[+]' : no_autinc);
        button.className = 'goog-buttonset-action-w';
        var td_button = $D.n_E("TD");
        td_button.align = "right";
        td_button.colSpan = trs[trs.length - 1].getElementsByTagName("TD").length;
        td_button.appendChild(button);
        var tr_button = $D.n_E("TR");
        tr_button.appendChild(td_button);
        body.appendChild(tr_button);
    }
}

function urlencode(str) {
    return encodeURIComponent(str + "").replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}

function autorefrescar(co_pagina, no_pagina, id_frawor, co_conten, ca_tamano, va_autref) {
    $D.g_ID("d" + co_pagina).style.display = "inline";
    var nodo = $D.g_ID("t" + co_pagina).parentNode;
    var r2 = $D.getTEXT($D.base() + "/workflow2/wf_pag_t.jsp?co_pagina=" + co_pagina + "&no_pagina=" + no_pagina + "&id_frawor=" + id_frawor + "&co_conten=" + co_conten + "&ca_tamano=" + ca_tamano + "&va_autref=" + va_autref);
    nodo.innerHTML = r2;
}

function cerrarsession() {
    $D.wait();
    $D.wait_msg("Cerrando su sesi&oacute;n");
    window.location = $D.base() + "/wl?xact=2";
}

function enviar_correo(id_element, id_correo) {
    $D.g_ID(id_element).innerHTML = "Enviando";
    var val = $D.getTEXT($D.base() + "/wfp?xact=17&p_id_correo=" + id_correo);
    if (val == "OK") {
        $D.g_ID(id_element).innerHTML = "Enviado";
    } else {
        $D.g_ID(id_element).innerHTML = "Fallido (" + val + ")";
    }
}

function valpagpospagi(co_pagina, id_frawor, co_conten, p1_name, p1_value, p2_name, p2_value) {
    var js = $D.getJSON($D.base() + "/wfp?xact=19&id_frawor=" + id_frawor + "&co_conten=" + co_conten + "&" + p1_name + "=" + p1_value + "&" + p2_name + "=" + p2_value);
    var js_o = $D.getJSON($D.base() + "/wfp?xact=18&id_frawor=" + id_frawor + "&co_conten=" + co_conten + "&co_pagina=" + co_pagina);
    for (var i = 0; i < js_o.length; i++) {
        var div_pagina = $D.g_ID("div_pagina_" + js_o[i].pfvalpagpospag);
        div_pagina.innerHTML = "Cargando...";
        var r = $D.getTEXT($D.base() + "/workflow2/wf_pag_i.jsp?co_pagina=" + js_o[i].pfvalpagpospag + "&no_pagina=&id_frawor=" + id_frawor + "&co_conten=" + co_conten);
        var td = null;
        var tr = null;
        try {
            td = div_pagina.parentNode;
        } catch (e) {
            td = div_pagina.getParent();
        }

        try {
            tr = td.parentNode;
        } catch (e) {
            tr = td.getParent();
        }

        if (tr.cells.length == 1) {
            if (tr.style.display != undefined)
                tr.style.display = 'table-row';
        } else {
            td.style.display = 'block';
        }

        div_pagina.style.display = "none";
        div_pagina.innerHTML = r;
        div_pagina.style.display = "block";
    }
}

//2014-01-09 Nuevas implementaciones
function play_audio(co_audio) {
    ReturnVal = window.showModalDialog("play.jsp?co_audio=" + co_audio, "argsVariable", "dialogWidth:450px; dialogHeight:50px; center:yes;directories:no;status:no; linemenubar:no;scrollbars:no;resizable:no;modal:yes;centerscreen");
}

/**
 * PAGREG46--->25-09-2014
 * */
var dt_pagreg46;
var t_div_pagreg46;
var t_ul_pagreg46;
var t_count_pagreg46;
var t_item_pagreg46 = false;
var t_cursor_pagreg46 = -1;
var t_total_pagreg46 = 0;
function pagreg46_onfocus(p_r) {
    dt_pagreg46 = options_gson[p_r.getAttribute("id").substring(0, p_r.getAttribute("id").length - 2)];
    t_div_pagreg46 = p_r.getAttribute("id").substring(0, p_r.getAttribute("id").length - 1) + "b";
    t_ul_pagreg46 = p_r.getAttribute("id").substring(0, p_r.getAttribute("id").length - 1) + "c";
    t_count_pagreg46 = 0;
    t_total_pagreg46 = 0;
    t_cursor_pagreg46 = -1;
    var sx = $D.g_ID(p_r.getAttribute("id").substring(0, p_r.getAttribute("id").length - 1) + "a");
    $D.g_ID(t_div_pagreg46).style.width = sx.clientWidth + "";
}

function pagreg46_onblur(p_r) {
    if (!t_item_pagreg46) {
        $D.g_ID(t_div_pagreg46).style.display = "none";
        return true;
    }
    return false;
}

function pagreg46_onkeyup(p_r, e) {
    var t_b = p_r.value;
    var t_l = t_b.length;
    switch (e.keyCode) {
        case 38://arriba
        {
            if (t_l > 0 & $D.g_ID(t_div_pagreg46).style.display == "block") {
//mover selecion hacia arriba
                var anterior = -1;
                if (t_cursor_pagreg46 == -1) {
                    anterior = -1;
                    t_cursor_pagreg46 = t_total_pagreg46;
                } else {
                    anterior = t_cursor_pagreg46;
                    if (t_cursor_pagreg46 - 1 == 0) {
                        t_cursor_pagreg46 = t_total_pagreg46;
                    } else {
                        t_cursor_pagreg46 = t_cursor_pagreg46 - 1;
                    }
                }

                var de = "" + ((p_r.getAttribute("id").substring(0, p_r.getAttribute("id").length - 2)) + "_" + (anterior - 1));
                var de2;
                try {
                    de2 = $D.g_ID(de);
                } catch (e) {
                    de2 = null;
                }

                if (de2 != null) {
                    var color = de2.getAttribute("color");
                    de2.style.backgroundColor = color;
                }

                var hacia = "" + ((p_r.getAttribute("id").substring(0, p_r.getAttribute("id").length - 2)) + "_" + (t_cursor_pagreg46 - 1));
                var hacia2 = $D.g_ID(hacia);
                hacia2.setAttribute("color", hacia2.style.backgroundColor);
                hacia2.style.backgroundColor = "#febb80";
            }
            break;
        }
        case 40://abajo
        {
            if (t_l > 0 & $D.g_ID(t_div_pagreg46).style.display == "block") {
//mover todo hacia abajo
                var anterior = -1;
                if (t_cursor_pagreg46 == -1) {
                    anterior = -1;
                    t_cursor_pagreg46 = 1;
                } else {
                    anterior = t_cursor_pagreg46;
                    if (t_cursor_pagreg46 + 1 > t_total_pagreg46) {
                        t_cursor_pagreg46 = 1;
                    } else {
                        t_cursor_pagreg46 = t_cursor_pagreg46 + 1;
                    }
                }

                var de = "" + ((p_r.getAttribute("id").substring(0, p_r.getAttribute("id").length - 2)) + "_" + (anterior - 1));
                var de2;
                try {
                    de2 = $D.g_ID(de);
                } catch (e) {
                    de2 = null;
                }
                if (de2 != null) {
                    var color = de2.getAttribute("color");
                    de2.style.backgroundColor = color;
                }

                var hacia = "" + ((p_r.getAttribute("id").substring(0, p_r.getAttribute("id").length - 2)) + "_" + (t_cursor_pagreg46 - 1));
                var hacia2 = $D.g_ID(hacia);
                hacia2.setAttribute("color", hacia2.style.backgroundColor);
                hacia2.style.backgroundColor = "#febb80";
            }
            break;
        }
        case 13://enter
        {
            if (t_l > 0 & $D.g_ID(t_div_pagreg46).style.display == "block") {
                if (t_cursor_pagreg46 > 0) {
                    var hacia = $D.g_ID((p_r.getAttribute("id").substring(0, p_r.getAttribute("id").length - 2)) + "_" + (t_cursor_pagreg46 - 1));
                    pagreg46_select(hacia)
                }
            }
            break;
        }
        default :
        {
            if (t_l > 0) {
                var texto = "";
                var palabra = "";
                var est = 0;
                var r = 0;
                t_total_pagreg46 = 0;
                for (var i = 0; i < dt_pagreg46.length; i++) {
                    if (dt_pagreg46[i].no_compag.indexOf(t_b) > -1 && t_count_pagreg46 < 10) {
                        palabra = dt_pagreg46[i].no_compag.replace(p_r.value, "<strong>" + p_r.value + "</strong>");
                        texto = texto + "<li id=\"" + (p_r.getAttribute("id").substring(0, p_r.getAttribute("id").length - 2)) + "_" + r + "\" style=\"background-color: " + (est == 0 ? "#ffffff" : "#f8f8f7") + "\" onclick=\"pagreg46_select(this)\" onmouseover=\"pagreg46_mouseover(this)\" onmouseout=\"pagreg46_mouseout(this)\" co_compag=\"" + dt_pagreg46[i].co_compag + "\" va_compag=\"" + dt_pagreg46[i].no_compag + "\" >" + palabra + "</li>";
                        t_count_pagreg46 = t_count_pagreg46 + 1;
                        if (est == 0)
                            est = 1;
                        else
                            est = 0;
                        t_total_pagreg46 = t_total_pagreg46 + 1;
                        r = r + 1;
                    }
                }
                $D.g_ID(t_div_pagreg46).style.display = "block";
                $D.g_ID(t_ul_pagreg46).innerHTML = texto;
                t_count_pagreg46 = 0;
            } else if (t_b.length == 0) {
                $D.g_ID(t_div_pagreg46).style.display = "none";
            }
            break;
        }
    }
}

function pagreg46_select(p_r) {
    var co_compag = p_r.getAttribute("co_compag");
    var va_compag = p_r.getAttribute("va_compag");
    var id_compag = p_r.getAttribute("id").substring(0, p_r.getAttribute("id").length - 2);
    $D.g_ID(id_compag).value = co_compag;
    $D.g_ID(id_compag + "_a").value = va_compag;
    $D.g_ID(id_compag + "_b").style.display = "none";
}

function pagreg46_mouseover(p_r) {
    t_item_pagreg46 = true;
}

function pagreg46_mouseout(p_r) {
    t_item_pagreg46 = false;
}

/*
 05/11/2014 : pagreg 12
 */
function update_time(id) {
    try {
        var horaI = $D.g_ID('ff_hora' + id);
        var hora = horaI.options[horaI.selectedIndex].value;
        var minutoI = $D.g_ID('ff_minuto' + id);
        var minuto = minutoI.options[minutoI.selectedIndex].value;
        var tiempoI = $D.g_ID('ff_tiempo' + id);
        var tiempo = tiempoI.options[tiempoI.selectedIndex].value;
        $D.g_ID('v' + id).value = hora + ":" + minuto + " " + tiempo;
    } catch (e) {/*alert('>'+e);*/
        console.log('error:' + e);
    }
}

/**
 09/12/2014: para todas las paginas tipo tabla
 */
function tabla_sombrear(id_tabla) {
    if (id_tabla) {
        var filas = $D.g_ID(id_tabla).tBodies[0].rows;
        for (var i in filas) {
            filas[i].onmouseover = function () {
                this.style.background = '#F8F8F7';
            };
            filas[i].onmouseout = function () {
                this.style.background = '';
            };
        }
    }
}

/**
 * 09/12/2014
 * PAGREG-40
 * */
function buildpagreg40(ID, V) {
    var ns = $D.g_ID(ID).value;
    ns = (ns.length == "") ? "" : ns.split("/");
    var nums = [];
    for (var i = 0; i < ns.length; i++) {
        var num = ns[i];
        if (num.length == 9 & !isNaN(num)) {
            nums[nums.length] = new Telefono(num);
        }
    }

    document.write("<ul id='" + ID + "_" + V + "_L' class='pagreg40'>");
    for (var i = 0; i < nums.length; i++) {
        var n = nums[i];
        document.write("<li>");
        document.write("<select id='" + ID + "_" + V + "_" + (i + 1) + "_C1' class='input2' onchange='pagreg40_C1(\"" + ID + "\",\"" + V + "\"," + (i + 1) + ")' >");
        document.write("<option value='C' " + (n.getTipo() == 'C' ? "selected" : "") + ">M&oacute;vil</option>");
        document.write("<option value='F' " + (n.getTipo() == 'F' ? "selected" : "") + ">Fijo</option>");
        document.write("</select>");
        document.write("<select id='" + ID + "_" + V + "_" + (i + 1) + "_C2'  class='input2' onchange='pagreg40_C2(\"" + ID + "\",\"" + V + "\"," + (i + 1) + ")' " + (n.getTipo() == 'C' ? "style='display:none'" : "") + ">");
        for (var o = 0; o < Departamentos.length; o++) {
            var dep = Departamentos[o];
            var select = "";
            if (dep.getCodigo() == n.getPrefijo()) {
                select = "selected";
            }
            document.write("<option value='" + dep.getCodigo() + "' " + select + " >" + dep.getNombre() + "</option>");
        }
        document.write("</select>");
        document.write("<input id='" + ID + "_" + V + "_" + (i + 1) + "_I'  type='text' value='" + n.getNumero() + "' size='9' maxlength='" + n.getMaxLength() + "' onkeyup='extractNumber(this, 0, true);' onkeypress='return blockNonNumbers(this, event, false, true);' onkeydown='if (event.keyCode == 13)event.keyCode = 9;' onblur='pagreg40_B(\"" + ID + "\",\"" + V + "\"," + (i + 1) + ")' >");
        document.write("<button id='" + ID + "_" + V + "_" + (i + 1) + "_B' class='boton40R' onclick='pagreg40_R(\"" + ID + "\",\"" + V + "\",\"" + (i + 1) + "\")' >");
        document.write("</button>");
        document.write("</li>");
    }

    document.write("<li>");
    document.write("<select id='" + ID + "_" + V + "_" + (nums.length + 1) + "_C1'  class='input2' onchange='pagreg40_C1(\"" + ID + "\",\"" + V + "\"," + (nums.length + 1) + ")' >");
    document.write("<option value='C' selected>M&oacute;vil</option>");
    document.write("<option value='F'>Fijo</option>");
    document.write("</select>");
    document.write("<select id='" + ID + "_" + V + "_" + (nums.length + 1) + "_C2'  class='input2' onchange='pagreg40_C2(\"" + ID + "\",\"" + V + "\"," + (nums.length + 1) + ")' style='display:none'>");
    for (var o = 0; o < Departamentos.length; o++) {
        var dep = Departamentos[o];
        var select = "";
        if (dep == '01') {
            select = "selected"
        }
        document.write("<option value='" + dep.getCodigo() + "' " + select + " >" + dep.getNombre() + "</option>");
    }
    document.write("</select>");
    document.write("<input id='" + ID + "_" + V + "_" + (nums.length + 1) + "_I'  type='text' value='' size='9' maxlength='9' onkeyup='extractNumber(this, 0, true);' onkeypress='return blockNonNumbers(this, event, false, true);' onkeydown='if (event.keyCode == 13)event.keyCode = 9;' onblur='pagreg40_B(\"" + ID + "\",\"" + V + "\"," + (nums.length + 1) + ")' >");
    document.write("<button id='" + ID + "_" + V + "_" + (nums.length + 1) + "_B' class='boton40A' onclick='pagreg40_A(\"" + ID + "\",\"" + V + "\"," + (i + 1) + ")' >");
    document.write("</button>");
    document.write("</li>");
    document.write("</ul>");
}

function pagreg40_C1(ID, V, I) {
    var c1 = $D.g_ID(ID + "_" + V + "_" + I + "_C1");
    var c2 = $D.g_ID(ID + "_" + V + "_" + I + "_C2");
    var In = $D.g_ID(ID + "_" + V + "_" + I + "_I");
    if (c1.options[c1.selectedIndex].value == 'C') {
        c2.style.display = 'none';
        In.setAttribute("maxlength", "9");
        In.value = "";
    } else {
        c2.style.display = 'inline-block';
        c2.value = "01";
        In.setAttribute("maxlength", "7");
        In.value = "";
    }
}

function pagreg40_C2(ID, V, I) {
    var C2 = $D.g_ID(ID + "_" + V + "_" + I + "_C2");
    var In = $D.g_ID(ID + "_" + V + "_" + I + "_I");
    if (C2.options[C2.selectedIndex].value == "01") {
        In.setAttribute("maxlength", "7");
    } else {
        In.setAttribute("maxlength", "6");
    }
}

function pagreg40_B(ID, V, I) {
    var L = $D.g_ID(ID + "_" + V + "_L");
    var IN = $D.g_ID(ID);
    IN.value = "";
    var Ls = L.getElementsByTagName("li");
    var R = [];
    for (var i = 0; i < Ls.length; i++) {
        var li = Ls[i];
        var C1 = li.getElementsByTagName("select")[0];
        var C2 = li.getElementsByTagName("select")[1];
        var I = li.getElementsByTagName("input")[0];
        if (C1.options[C1.selectedIndex].value == "C" & I.value.length == 9) {
            R[R.length] = I.value;
        } else if ((C1.options[C1.selectedIndex].value == "F") & (C2.options[C2.selectedIndex].value == "01") & (I.value.length == 7)) {
            R[R.length] = C2.options[C2.selectedIndex].value + I.value;
        } else if ((C1.options[C1.selectedIndex].value == "F") & (C2.options[C2.selectedIndex].value != "01") & (I.value.length == 6)) {
            R[R.length] = C2.options[C2.selectedIndex].value + I.value;
        }
    }
    if (R.length > 0) {
        IN.value = R.join("/");
    }
}

function pagreg40_R(ID, V, I) {
    var P = $D.g_ID(ID + "_" + V + "_" + I + "_I").parentNode;
    if (P.tagName = "LI") {
        P.parentNode.removeChild(P);
        pagreg40_B(ID, V, I);
    }
}

function pagreg40_A(ID, V, I) {
    var L = $D.g_ID(ID + "_" + V + "_L");
    var B = $D.g_ID(ID + "_" + V + "_" + I + "_B");
    var Cn = "";
    Cn = Cn + "<select id='" + ID + "_" + V + "_" + (I + 1) + "_C1'  class='input2' onchange='pagreg40_C1(\"" + ID + "\",\"" + V + "\"," + (I + 1) + ")' >";
    Cn = Cn + "<option value='C' selected>M&oacute;vil</option>";
    Cn = Cn + "<option value='F'>Fijo</option>";
    Cn = Cn + "</select>";
    Cn = Cn + "<select id='" + ID + "_" + V + "_" + (I + 1) + "_C2'  class='input2' onchange='pagreg40_C2(\"" + ID + "\",\"" + V + "\"," + (I + 1) + ")' style='display:none'>";
    for (var o = 0; o < Departamentos.length; o++) {
        var dep = Departamentos[o];
        var select = "";
        if (dep == '01') {
            select = "selected"
        }
        Cn = Cn + "<option value='" + dep.getCodigo() + "' " + select + " >" + dep.getNombre() + "</option>";
    }
    Cn = Cn + "</select>";
    Cn = Cn + "<input id='" + ID + "_" + V + "_" + (I + 1) + "_I'  type='text' value='' size='9' maxlength='9' onkeyup='extractNumber(this, 0, true);' onkeypress='return blockNonNumbers(this, event, false, true);' onkeydown='if (event.keyCode == 13)event.keyCode = 9;' onblur='pagreg40_B(\"" + ID + "\",\"" + V + "\"," + (I + 1) + ")' >";
    Cn = Cn + "<button id='" + ID + "_" + V + "_" + (I + 1) + "_B' class='boton40A' onclick='pagreg40_A(\"" + ID + "\",\"" + V + "\",\"" + (I + 1) + "\")' >";
    Cn = Cn + "</button>";
    var l1 = $D.n_E("LI");
    l1.innerHTML = Cn;
    L.appendChild(l1);
    B.setAttribute("onclick", B.getAttribute("onclick").replace("A", "R"))
    B.setAttribute("class", "boton40R")
}

/**
 * 09/12/2014
 * PAGREG-8
 * */
function buildpagreg8(ID, V, P, E) {
    var ns = $D.g_ID(ID).value;
    var opts = options_gson[ID];
    var inx = 0;
    ns = (ns.length == "") ? "" : ns.split(",");
    document.write("<ul id='" + ID + "_" + V + "_L' class='pagreg8'>");
    for (var i = 0; i < ns.length; i++) {
        if (ns[i].length > 0) {
            for (var o = 0; o < opts.length; o++) {
                if (opts[o].co_compag == ns[i]) {
                    document.write("<li><b>-</b> " + opts[o].no_compag + "</li>");
                    o = opts.length;
                    inx = inx + 1;
                }
            }
        }
    }
    if (E) {
        document.write("<li>");
        document.write("<button onclick='verselectormultiple(\"" + ID + "\",\"" + V + "\",\"" + P + "\")' class='boton8'>");
        document.write(inx == 0 ? "Agregar" : "Editar");
        document.write("</button>");
        document.write("</li>");
        document.write("</ul>");
    }
}

/**
 * 09/12/2014
 * PAGREG-45
 * */
function pagreg45_depart(ele, vd) {
    var id_provin = ele.getAttribute("id").replace("depart", "provin");
    var az_provin = $D.g_ID(id_provin);
    var az_provin_onchange = az_provin.getAttribute("onchange");
    console.log("inicio con=" + pagreg);
    az_provin.removeAttribute("onchange");
    //------------------
    az_provin.setAttribute("disabled", "disabled");
    az_provin.innerHTML = "";
    var option = empty_combo("- - PROVINCIA - -", "00");
    option.setAttribute("selected", "selected");
    az_provin.appendChild(option);
    if (ele.value != '00') {
        var ls_provin = $D.getJSON($D.base() + "/wfp?xact=20&co_depart=" + ele.value);
        for (var i = 0; i < ls_provin.length; i++) {
            az_provin.appendChild(empty_combo(ls_provin[i].no_provin, ls_provin[i].co_provin));
        }
        az_provin.removeAttribute("disabled");
    }

    az_provin.setAttribute("onchange", az_provin_onchange);
    az_provin.onchange();
}

function pagreg45_provin(ele, vd) {
    var co_depart = $D.g_ID(ele.getAttribute("id").replace("provin", "depart")).value;
    var id_distri = ele.getAttribute("id").replace("provin", "distri");
    var az_distri = $D.g_ID(id_distri);
    var az_distri_onchange = az_distri.getAttribute("onchange");
    az_distri.removeAttribute("onchange");
    //----------------------------
    az_distri.setAttribute("disabled", "disabled");
    az_distri.innerHTML = "";
    var option = empty_combo("- - DISTRITO - -", "00");
    option.setAttribute("selected", "selected");
    az_distri.appendChild(option);
    if (ele.value == '00') {
        $D.g_ID(ele.getAttribute("id").replace("_provin", "")).value = "";
    } else {
        var ls_distri = $D.getJSON($D.base() + "/wfp?xact=20&co_depart=" + co_depart + "&co_provin=" + ele.value);
        for (var i = 0; i < ls_distri.length; i++) {
            az_distri.appendChild(empty_combo(ls_distri[i].no_distri, ls_distri[i].co_distri));
        }
        az_distri.removeAttribute("disabled");
    }

    az_distri.setAttribute("onchange", az_distri_onchange);
    az_distri.onchange();
}

function pagreg45_distri(ele, vd) {
    var co_depart = $D.g_ID(ele.getAttribute("id").replace("distri", "depart")).value;
    var co_provin = $D.g_ID(ele.getAttribute("id").replace("distri", "provin")).value;
    var co_distri = ele.value;
    if (co_distri != "00")
        $D.g_ID(ele.getAttribute("id").replace("_distri", "")).value = co_depart + co_provin + co_distri;
    else
        $D.g_ID(ele.getAttribute("id").replace("_distri", "")).value = "";
}

function pagreg45(id, va) {
    va = va + "";
    if (va.length == 6) {
        var az_depart = $D.g_ID(id + "_depart");
        var az_depart_onchange = az_depart.getAttribute("onchange");
        az_depart.removeAttribute("onchange");
        az_depart.removeAttribute("disabled");
        var az_provin = $D.g_ID(id + "_provin");
        var az_provin_onchange = az_provin.getAttribute("onchange");
        az_provin.removeAttribute("onchange");
        az_provin.removeAttribute("disabled");
        var az_distri = $D.g_ID(id + "_distri");
        var az_distri_onchange = az_distri.getAttribute("onchange");
        az_distri.removeAttribute("onchange");
        az_distri.removeAttribute("disabled");
        for (var i = 0; i < az_depart.options.length; i++) {
            if (az_depart.options.item(i).value == va.substr(0, 2)) {
                az_depart.options[i].setAttribute("selected", "selected");
            }
        }
        az_provin.innerHTML = "";
        az_provin.appendChild(empty_combo("- - PROVINCIA - -", "00"));
        var ls_provin = $D.getJSON($D.base() + "/wfp?xact=20&co_depart=" + va.substr(0, 2));
        for (var i = 0; i < ls_provin.length; i++) {
            var option = empty_combo(ls_provin[i].no_provin, ls_provin[i].co_provin);
            if (ls_provin[i].co_provin == va.substr(2, 2)) {
                option.setAttribute("selected", "selected");
            }
            az_provin.appendChild(option);
        }


        az_distri.innerHTML = "";
        az_distri.appendChild(empty_combo("- - DISTRITO - -", "00"));
        var ls_distri = $D.getJSON($D.base() + "/wfp?xact=20&co_depart=" + va.substr(0, 2) + "&co_provin=" + va.substr(4, 2));
        for (var i = 0; i < ls_distri.length; i++) {
            var option = empty_combo(ls_distri[i].no_distri, ls_distri[i].co_distri);
            if (ls_distri[i].co_distri == va.substr(4, 2)) {
                option.setAttribute("selected", "selected");
            }
            az_distri.appendChild(option);
        }

        az_depart.setAttribute("onchange", az_depart_onchange);
        az_provin.setAttribute("onchange", az_provin_onchange);
        az_distri.setAttribute("onchange", az_distri_onchange);
        az_distri.onchange();
    }
}

function empty_combo(tx, va) {
    var option = $D.n_E("OPTION");
    option.innerHTML = tx;
    option.value = va;
    return option;
}

/*
 * PAGREG 44 : 11/12/2014
 * 
 */
function pagreg44(id) {
    $D.lock();
//    $D.wait_msg("Consultando...")
    $D.wait("Consultando...");
    var rpta = $D.getJSONE("http://sd3.accesocrediticio.com:8070/wservices/SunarpServlet?placa=" + $D.g_ID('de' + id).value);
    $D.g_ID("sh2" + id).style.display = "none"
    $D.g_ID("de" + id).style.display = "none"
    $D.g_ID("sh" + id).style.display = "inline-block"
    $D.g_ID("sh3" + id).style.display = "inline-block"
    var tjson = "<ul style='margin:0px;padding:0px;'><li>Placa: <b>" + rpta.placa + "</b></li>" +
            "<li>Serie: <b>" + rpta.serie + "</b></li>" +
            "<li>VIN: <b>" + rpta.vim + "</b></li>" +
            "<li>Motor: <b>" + rpta.motor + "</b></li>" +
            "<li>Marca <b>" + rpta.marca + "</b></li>" +
            "<li>Modelo: <b>" + rpta.modelo + "</b></li>" +
            "<li>Color: <b>" + rpta.color + "</b></li>";
    if (rpta.propietarios.length == 1) {
        tjson = tjson + "<li>Propietario: <b>" + rpta.propietarios[0] + "</b></li>";
    } else if (rpta.propietarios.length > 1) {
        for (var i = 0; i < rpta.propietarios.length; i++) {
            tjson = tjson + "<li>Propietario " + (i + 1) + ": <b>" + rpta.propietarios[i] + "</b></li>";
        }
    }
    tjson = tjson + "</ul>";
    $D.g_ID("sh" + id).innerHTML = tjson;
    $D.g_ID("v" + id).value = JSON.stringify(rpta);
    $D.g_ID("sh1" + id).style.width = "285px";
    $D.wakeup();
    $D.unlock();
}

function pagreg44_r(id) {
    $D.g_ID("sh3" + id).style.display = "none";
    $D.g_ID("sh2" + id).style.display = "inline-block";
    $D.g_ID("v" + id).value = "";
    $D.g_ID("sh" + id).innerHTML = "";
    $D.g_ID("de" + id).style.display = "inherit";
    $D.g_ID("de" + id).focus();
    $D.g_ID("sh1" + id).style.width = "60px";
}
